From: Andrew Falanga on
Hi,

This is not the first time I've used unsafe code in C# projects.
Usually, I simply check the box in the project properties telling it
to allow unsafe code. I've done that for this project, yet VS is
telling that, "Unsafe code may only appear in compiling with /
unsafe." So, here's the command line being used to compile:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /
nowarn:618,1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /
warn:4


I'm betting that this is complaining because the switch that appears
above is "/unsafe-" instead of "/unsafe". So, how can I edit the
build command line? I haven't found how to do this anywhere yet.
This is highly frustrating.

Andy
From: Peter Duniho on
Andrew Falanga wrote:
> Hi,
>
> This is not the first time I've used unsafe code in C# projects.
> Usually, I simply check the box in the project properties telling it
> to allow unsafe code. I've done that for this project, yet VS is
> telling that, "Unsafe code may only appear in compiling with /
> unsafe." So, here's the command line being used to compile:
>
> C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /
> nowarn:618,1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /
> warn:4
>
>
> I'm betting that this is complaining because the switch that appears
> above is "/unsafe-" instead of "/unsafe". So, how can I edit the
> build command line? I haven't found how to do this anywhere yet.
> This is highly frustrating.

AFAIK, you can't customize the csc.exe command line in VS, the way you
can with cl.exe. As a last-ditch work-around, you could always compile
from the command prompt, and provide whatever switches are necessary.

That said, my experience has been that the "/unsafe" switch is always
present, and is either "/unsafe-" or "/unsafe+" depending on the project
configuration.

I've also never seen it not work when set in the project properties, but
I admit it's not something that comes up a lot so the fact that I
haven't seen it not work doesn't necessarily mean much. :)

So, I guess my first suggestion would be to go back and double-check to
make sure you have really checked the "Allow unsafe code" checkbox in
the Build tab of the project settings.

If VS is really simply not respecting that setting, then my next
suggestion would be to create a brand new solution and project, and see
if you can get it to work there (just to be safe, make sure you do that
with a freshly-started instance of VS).

If it works fine with a fresh project, then there's probably something
messed up with that particular project or the user settings for the
project. First thing to try in that case would be to delete the hidden
..suo file. I don't know why, but it seems like whenever VS is doing
something weird, a lot of the time just deleting that file fixes it (it
caches user-specific settings for the solution, which I wouldn't think
would affect builds, but it winds up doing so somehow anyway).

If it looks like something wrong with the project but deleting the .suo
file doesn't fix it, then it might be something wrong in the .csproj
file itself. IMHO, the easiest way to fix something like that is just
to delete the .csproj and create a new project from scratch, adding the
existing .cs files and other project members to the new project.

Of course, if even in a fresh project with a freshly-started instance of
VS you still can't get that checkbox to produce the correct csc.exe
switch, then it sounds like there may be something wrong with the VS
install somehow. There's a command-line switch you can use when
starting up VS that will clear all the user settings back to their
defaults and reset some things, but I can't recall what it is right now.
Probably you can find with Google though.

Hopefully it won't require anything so drastic though.

Pete
From: Andrew Falanga on
On Jun 10, 12:04 am, Peter Duniho <NpOeStPe...(a)NnOwSlPiAnMk.com>
wrote:
> Andrew Falanga wrote:
> > Hi,
>
> > This is not the first time I've used unsafe code in C# projects.
> > Usually, I simply check the box in the project properties telling it
> > to allow unsafe code.  I've done that for this project, yet VS is
> > telling that, "Unsafe code may only appear in compiling with /
> > unsafe."  So, here's the command line being used to compile:
>
> > C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /
> > nowarn:618,1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /
> > warn:4
>
> > I'm betting that this is complaining because the switch that appears
> > above is "/unsafe-" instead of "/unsafe".  So, how can I edit the
> > build command line?  I haven't found how to do this anywhere yet.
> > This is highly frustrating.
>
> AFAIK, you can't customize the csc.exe command line in VS, the way you
> can with cl.exe.  As a last-ditch work-around, you could always compile
> from the command prompt, and provide whatever switches are necessary.
>
> That said, my experience has been that the "/unsafe" switch is always
> present, and is either "/unsafe-" or "/unsafe+" depending on the project
> configuration.
>
> I've also never seen it not work when set in the project properties, but
> I admit it's not something that comes up a lot so the fact that I
> haven't seen it not work doesn't necessarily mean much.  :)
>
> So, I guess my first suggestion would be to go back and double-check to
> make sure you have really checked the "Allow unsafe code" checkbox in
> the Build tab of the project settings.
>
> If VS is really simply not respecting that setting, then my next
> suggestion would be to create a brand new solution and project, and see
> if you can get it to work there (just to be safe, make sure you do that
> with a freshly-started instance of VS).
>
> If it works fine with a fresh project, then there's probably something
> messed up with that particular project or the user settings for the
> project.  First thing to try in that case would be to delete the hidden
> .suo file.  I don't know why, but it seems like whenever VS is doing
> something weird, a lot of the time just deleting that file fixes it (it
> caches user-specific settings for the solution, which I wouldn't think
> would affect builds, but it winds up doing so somehow anyway).
>
> If it looks like something wrong with the project but deleting the .suo
> file doesn't fix it, then it might be something wrong in the .csproj
> file itself.  IMHO, the easiest way to fix something like that is just
> to delete the .csproj and create a new project from scratch, adding the
> existing .cs files and other project members to the new project.
>
> Of course, if even in a fresh project with a freshly-started instance of
> VS you still can't get that checkbox to produce the correct csc.exe
> switch, then it sounds like there may be something wrong with the VS
> install somehow.  There's a command-line switch you can use when
> starting up VS that will clear all the user settings back to their
> defaults and reset some things, but I can't recall what it is right now.
>   Probably you can find with Google though.
>
> Hopefully it won't require anything so drastic though.
>
> Pete

Pete,

Thanks for the detailed reply. I hadn't thought about the *.suo
file. I'm going to try that option first. I'll post back what
happens.

Andy
From: Andrew Falanga on
On Jun 10, 9:29 am, Andrew Falanga <af300...(a)gmail.com> wrote:
> On Jun 10, 12:04 am, Peter Duniho <NpOeStPe...(a)NnOwSlPiAnMk.com>
> wrote:
>
>
>
> > Andrew Falanga wrote:
> > > Hi,
>
> > > This is not the first time I've used unsafe code in C# projects.
> > > Usually, I simply check the box in the project properties telling it
> > > to allow unsafe code.  I've done that for this project, yet VS is
> > > telling that, "Unsafe code may only appear in compiling with /
> > > unsafe."  So, here's the command line being used to compile:
>
> > > C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /unsafe- /
> > > nowarn:618,1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /
> > > warn:4
>
> > > I'm betting that this is complaining because the switch that appears
> > > above is "/unsafe-" instead of "/unsafe".  So, how can I edit the
> > > build command line?  I haven't found how to do this anywhere yet.
> > > This is highly frustrating.
>
> > AFAIK, you can't customize the csc.exe command line in VS, the way you
> > can with cl.exe.  As a last-ditch work-around, you could always compile
> > from the command prompt, and provide whatever switches are necessary.
>
> > That said, my experience has been that the "/unsafe" switch is always
> > present, and is either "/unsafe-" or "/unsafe+" depending on the project
> > configuration.
>
> > I've also never seen it not work when set in the project properties, but
> > I admit it's not something that comes up a lot so the fact that I
> > haven't seen it not work doesn't necessarily mean much.  :)
>
> > So, I guess my first suggestion would be to go back and double-check to
> > make sure you have really checked the "Allow unsafe code" checkbox in
> > the Build tab of the project settings.
>
> > If VS is really simply not respecting that setting, then my next
> > suggestion would be to create a brand new solution and project, and see
> > if you can get it to work there (just to be safe, make sure you do that
> > with a freshly-started instance of VS).
>
> > If it works fine with a fresh project, then there's probably something
> > messed up with that particular project or the user settings for the
> > project.  First thing to try in that case would be to delete the hidden
> > .suo file.  I don't know why, but it seems like whenever VS is doing
> > something weird, a lot of the time just deleting that file fixes it (it
> > caches user-specific settings for the solution, which I wouldn't think
> > would affect builds, but it winds up doing so somehow anyway).
>
> > If it looks like something wrong with the project but deleting the .suo
> > file doesn't fix it, then it might be something wrong in the .csproj
> > file itself.  IMHO, the easiest way to fix something like that is just
> > to delete the .csproj and create a new project from scratch, adding the
> > existing .cs files and other project members to the new project.
>
> > Of course, if even in a fresh project with a freshly-started instance of
> > VS you still can't get that checkbox to produce the correct csc.exe
> > switch, then it sounds like there may be something wrong with the VS
> > install somehow.  There's a command-line switch you can use when
> > starting up VS that will clear all the user settings back to their
> > defaults and reset some things, but I can't recall what it is right now..
> >   Probably you can find with Google though.
>
> > Hopefully it won't require anything so drastic though.
>
> > Pete
>
> Pete,
>
> Thanks for the detailed reply.  I hadn't thought about the *.suo
> file.  I'm going to try that option first.  I'll post back what
> happens.
>
> Andy

Well, as promised, here's the post for "posterity." Unfortunately, I
never did figure out why the compiler kept telling me that I cannot
compiler unsafe code blocks without the, "Allow unsafe code," property
checked in the project properties. This property was checked and
verified by opening the project config file in a text editor (long
live Vim). I tried the path of deleting the *.suo file, but this did
not fix the issue. To be fair to the system, however, I'm not playing
with a "simple" VS solution either. The solution was built with the
requirements here at work, and the build environment isn't "stock."
So, who knows what might have been happening there.

At any rate, I did find a managed solution for writing data into those
pointers thus rendering the unsafe code blocks unnecessary. Should
you find this thread in a groups search, please see the responses I
got from my question in thread entitled, "How to assign a value to
memory pointed by an IntPtr."

Thanks again Pete,
Andy