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:
The problem is, my Project Properties window doesn't look anything like that or have that option. Mine looks like this:
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:
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.