0

I'm trying to allow access to the unsafe access modifier so I can take advantage of pointers to store memory addresses in my ASP.NET C# Web Forms Site. I've read plenty of documentation saying there is a checkbox you can check to allow unsafe code by going to Project > Properties > Build. An image of that window is something like this:

Unsafe checkbox

The problem is, my Project Properties window doesn't look anything like that or have that option. Mine looks like this:

My Window

When I go to Debug > website_name Properties (instead of Project Properties), I actually do have a Build tab, but it doesn't have a checkbox for unsafe code either. It looks like this:

My Window

So that eliminates my possibilities of using any checkbox - maybe it doesn't come with web apps or wasn't part of my installation? Some articles say they do come in web-based apps, but I think they are only for Windows (WPF) and console apps as stated in this article: how to add unsafe keyword in web based asp.net application c#. Either way, that left me with a couple other options, and they were to allow /unsafe to the compiler explicitly. One is to go the Web.config file and add the following lines:

<system.codedom>
   <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/unsafe" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   </compilers>
</system.codedom>

That hasn't worked. Most of the docs I found for the Web.config compilers came back in years like 2010 and 2011 - like in the one I listed above, so they had version 2.0.0.0. This code can easily have changed since then, and as you can see in my last picture, my target framework is 4.5.2, so I used version 4.0.0.0, but still no luck. One last explicit way of trying to allow the unsafe keyword is by entering in the following command in the Visual Studio Developer Command Prompt:

csc /unsafe Your_Web_Form.aspx

That command gave me an error for each line of my .aspx file. I would really appreciate help on this issue, and I'm sure it could help many others who have recently had this problem and are looking for more recent documentation.

Max Voisard
  • 1,685
  • 1
  • 8
  • 18
  • 1
    Any chance you stop using "web site" template ("This template does not produce a project file and has limited MSBuild support") and switch to normal "ASP.Net Web Application" that actually use projects? – Alexei Levenkov Apr 05 '19 at 21:11
  • You could edit your `.csproj` file. Under ` – user3670011 Apr 05 '19 at 21:13
  • 1
    @user3670011 ??? OP does not have project files... otherwise they would be able to use project properties just fine. – Alexei Levenkov Apr 05 '19 at 21:14
  • Alexei Levenkov - thank you, it worked! I remember now I used a Web Forms Site template for my solution, and now I see that site solutions are not projects but Web Application templates are. The window I was looking for came up. – Max Voisard Apr 05 '19 at 21:29
  • 1
    What do you need pointers for in a Web Forms app? – mason Apr 05 '19 at 21:44
  • lol it's funny you ask. There's no particular reason, I'm just using it as a unique module to show the user what memory address a string is stored in by converting it to an integer, along with the hash codes for that string, like MD5, SHA1, and SHA256 checksums. – Max Voisard Apr 05 '19 at 21:56

0 Answers0