How does one make VS compile unsafe code

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
0
Andrew
6/9/2010 10:11:37 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

3 Replies
836 Views

Similar Articles

[PageSpeed] 5

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
0
Peter
6/10/2010 6:04:18 AM
On Jun 10, 12:04=A0am, Peter Duniho <NpOeStPe...@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. =A0I've done that for this project, yet VS is
> > telling that, "Unsafe code may only appear in compiling with /
> > unsafe." =A0So, 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". =A0So, how can I edit the
> > build command line? =A0I 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. =A0As 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. =A0:)
>
> 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. =A0First thing to try in that case would be to delete the hidden
> .suo file. =A0I 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. =A0IMHO, 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. =A0There'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.
> =A0 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
0
Andrew
6/10/2010 3:29:01 PM
On Jun 10, 9:29=A0am, Andrew Falanga <af300...@gmail.com> wrote:
> On Jun 10, 12:04=A0am, Peter Duniho <NpOeStPe...@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. =A0I've done that for this project, yet VS is
> > > telling that, "Unsafe code may only appear in compiling with /
> > > unsafe." =A0So, 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". =A0So, how can I edit the
> > > build command line? =A0I 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. =A0As a last-ditch work-around, you could always compi=
le
> > 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 projec=
t
> > configuration.
>
> > I've also never seen it not work when set in the project properties, bu=
t
> > 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. =A0:)
>
> > 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. =A0First thing to try in that case would be to delete the hidd=
en
> > .suo file. =A0I 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. =A0IMHO, the easiest way to fix something like that is jus=
t
> > 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 o=
f
> > 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. =A0There'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=
..
> > =A0 Probably you can find with Google though.
>
> > Hopefully it won't require anything so drastic though.
>
> > Pete
>
> Pete,
>
> Thanks for the detailed reply. =A0I hadn't thought about the *.suo
> file. =A0I'm going to try that option first. =A0I'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
0
Andrew
6/11/2010 3:52:20 PM
Reply:

Similar Artilces:

Font Color codes
Hi, It someboby know the colors code for required (red) and recomended (blue) field? Thanks, Sylvie Required (Red):#990000; Desired (Blue):#000099; More info: http://msdn.microsoft.com/library/en-us/CrmSdk1_2/htm/v1d2stylesheet.asp?frame=true Hope this helps. []'s Vin�cius Pitta Lima de Ara�jo "Si" <anonymous@discussions.microsoft.com> escreveu na mensagem news:283eb01c46430$aa869110$a401280a@phx.gbl... > Hi, > > It someboby know the colors code for required (red) and > recomended (blue) field? > > Thanks, > > Sylvie WOW, exactly what I ne...

How does one view a document created in Publisher.
I have gotten a document (calendar) in .pub format. Word does not recognize it. Is there a viewer? What's the link? I have Office 2000 with the converters installed. Collins wrote: >I have gotten a document (calendar) in .pub format. Word > does not recognize it. Is there a viewer? What's the > link? I have Office 2000 with the converters installed. ==================================== There is no viewer for Publisher files. Maybe you could ask the sender to convert it to a .pdf file. Or you could order the Trial version of Pub2003... which will still function as a viewer a...

One domain on exchange server not accepting connections
I setup a second domain on an Exchange 2003 server, and thought everything was working. Now, though, mail going to the second domain gets rejected, but mail going to the original domain is still working. I can telnet to the original domain, but not to the second domain. I've checked everything I know to check (I've setup plenty of domains on Exchange servers, so I believe I've gotten the setting correct), but I just can't get it to work. The MX records are correct, and mail.theseconddomain.com resolves to the right IP address (the same IP as mail.originaldomain.com), so it sh...

How to make autostart programs in USB stick memory
Hi. Some said, when USB memory stick putting on PC, it can start autostart programs, like Autorun.inf of CD-R. Does any know how to do it? Thanks, M.M. M.Miura wrote: > Some said, when USB memory stick putting on PC, it can start > autostart programs, like Autorun.inf of CD-R. Does any know > how to do it? Same way. Most systems these days have autorun disabled. ;-) (for good reason.) -- Shenan Stanley MS-MVP -- How To Ask Questions The Smart Way http://www.catb.org/~esr/faqs/smart-questions.html M.Miura wrote: > Hi. > > Some ...

Unknown Error 80070659 with code 659
Windows Server 2008 SP1 Terminal Services IE8 I have looked online for this code and I cannot seem to find anything. I have 7 updates installed sucessfully and 25 unsuccessfully. The unsuccessful ones all appear to be either office 2007 updates or dot net updates and XML updates. There is one pending IE8 update. Any thoughts? -- MTI Business Services 61390388803 ...

Get $500 to your PAYPAL Account by just one CLICK)
i have hidden the form of getting $500 to your PAYPAL ACCOUNT....CLICK on the IMAGE which is on the RIGHT SIDE of the website http://tricks-4u.4-all.org/ ...

Adding to existing code (Clarification of earlier post)
After rereading my earlier post, I find that I wasn't very clear. I'll try again. My existing code works to give me the sum of all Weeks Service where the Department Name is equal to the Current Department Name and I do want to keep that code. In addition to that code though, I need to add, I'm guessing, an "IF Statement" that will provide me with the sum of ALL Weeks Service of ALL Department Name IF the Current Department Name is equal to "Reserves". Example: Department Name Weeks Service Millwright ...

Compile Error in Visual Basic: Main Module?
I just started getting this pop-up applet - "Compile Error in Visual Basic: Main Module?"- whenever I open Excel 2000 - if I just click OK, then Excel opens and everything is fine. I tried to do a repair function using the Office 2000 disks, but it is still there. Google search did not find this error message exactly except for a MAC user. Ideas? That is probably a badly written addin, either installed (tools > addin menu) or a file residing in you startup folder (tools > options menu to find where that is). Those things are typically scanner software or acrobat/pdf wri...

how i can make the numbers
hi i am fatih fistly sorry my english is not good my trouble is haw can i will write the number of the contribution for example 1.000.000.000 =yaziyla(b42) (one milyar) and tahan my office version is turkish version thank you so your company will interesting my problem Fatih, If I understand you correctly, you want a formula to translate numbers to words (in Turkish). Laurent Longre has a language version of an function which offers this capability. It is at http://longre.free.fr/english/ I don't know if it supports Turkish, but if not, send me the Turkish words for all...

Can you make a crossword puzzle by putting the words in?
I have to make a crossword puzzle for one of my classes, and was wondering if there is a program on my computer that will show me how to make the crossword puzzles. If you can help that would be great. Perhaps this MS link would be of interest: http://www.microsoft.com/education/Crossword.aspx "Design a Crossword Puzzle in Microsoft Excel" -- Rgds Max xl 97 --- GMT+8, 1° 22' N 103° 45' E xdemechanik <at>yahoo<dot>com ---- "Kat" wrote: > I have to make a crossword puzzle for one of my classes, and was wondering if > there is ...

Bar Chart (2D) won't let me 'gap' one bar behind the other?
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I have a nice, functioning bar chart that has 2 data fields: ACTUAL and BUDGET. <br><br>Actual is on one axis and Budget is on the 2nd axis. <br><br>These charts look nice side by side but I want one bar to be partly behind the other. <br><br>So, I select a data set. <br> Choose Format Data Series <br> Options <br> Overlap... (and no matter what value I choose, I can't overlap)???? <br><br>But, if I can adjust the Gap Width. <br><...

excel chart showing movable graph at what point we make a profit
in a business would like to make a chart based on accumulated Earnings & Profit/Loss for year to date, perhaps movable showing our break even point and by moving chart to a another earnings figure what profit we should make. For example put in earnings for YTD Profit/Loss YTD then I can move the earnings part of the chart to show what our profit would be for a given earnings figure. Alternatively If For example if we earn $200 for year so far and profit is $0 but any amount over that is 18% profit so I can move chart line to say $240 and it will say what profit I will make. Hope ...

Converting from VS 2003 to VS 2005
I have recently converted a fully working application from VS 2003 to VS 2005. I now seem to have lost XP Themes and none of my combo boxes are working. Does anyone have any ideas? Chris "Chris Day" ha scritto nel messaggio news:20089248422chris.day@onwight.net... >I have recently converted a fully working application from VS 2003 to VS >2005. I now seem to have lost XP Themes and none of my combo boxes are >working. Does anyone have any ideas? Hi Chris, do you compile in Unicode mode in VC++ 2005? I'm not sure, but I seem to recall that VC++2005 removes new XP ...

how do you make pictures your slide background
iam am trying to make a map of the hundred years war my actual background not tryng to make a picture slideshow in ppt. 2003, in the same way you can change the back ground fill or make a whole new slide design also how do you make i template in ppt. i kinda forgot This should get you started: Design efficiently with masters: http://office.microsoft.com/training/training.aspx?AssetID=RC011536491033 Lucy -- Lucy Thomson PowerPoint MVP MOS Master Instructor www.aneasiertomorrow.com.au "ppthelp" <ppthelp@discussions.microsoft.com> wrote in message ...

Outlook keeps making itself Default
Hi, Everytime I start Outlook it takes over as default for email and addresses even though I have that option unchecked in outlook, and in IE I set OE Express as default, yet each time I launch outlook it takes over as Default, any ideas TIA Wayne ...

can I make cell "yes" equal 1, "no" equal 0
in another cell? =IF(AND(A1<>"yes",A1<>"no"),"",(A1="yes")*1+(A1="no")*0) -- HTH RP (remove nothere from the email address if mailing direct) "can I make cell yes equal 1, no equa" <can I make cell "yes" equal 1, "no" equa@discussions.microsoft.com> wrote in message news:8E222344-E390-4D39-B82D-39586CC55A64@microsoft.com... > Picky but I don't think that you need the " +(A1="no")*0 " Just =IF(AND(A1<>"yes",A1<>"no"),"&quo...

HOWTO Make CDialog's with ActiveX in a LIB.
HOWTO Make CDialog's with ActiveX in a LIB. Please help, I'm having a heck of a time trying to get a CDialog derrived class host a single ActiveX control (the CWebBrowser control), from a static LIB. When the OnInitDialog for the class call's CDialog::OnInitDialog it bombs inside the DoDataExchange for the DDX_Control of the control. Specifically at dlgdata.cpp line 43, with the following ASSERT: TRACE(traceAppMsg, 0, "Error: no data exchange control with ID 0x%04X.\n", nIDC); The reason why this ASSERT fails is because the CDialog's "m_pCtrlCont" i...

How do I make this formula?
I have an Excel worksheet to track my 401k performance. I have a row for Date, the Balance corresponding to each date, Contributions, a formula to calculate my Total Contributions, and a formula to calculate my Total Gain/Loss. My question is, how to I get my Gain/Loss formula to update corresponding to a new Date/Balance? Is there a formula function to make the formula ignore Column data in the previous Rows? Thanks! There will be, just add/subtract items from that row. Can you show us an example with data. -- HTH RP (remove nothere from the email address if mailing direct) &...

How do I link one database inside another?
I am wanting to be able to click on a button in one database and open another database. Thanks. Why? As in "why open a separate database?" Would it be sufficient to have the tables from both databases linked into a common front-end file? Regards Jeff Boyce Microsoft Office/Access MVP "julrankay" <julrankay@discussions.microsoft.com> wrote in message news:C6DEF9FE-C983-4503-BCD8-75FF0354A533@microsoft.com... > I am wanting to be able to click on a button in one database and open > another database. Thanks. > if you used Access Data Projects then...

POS is making me angry!!!
This program has not seemes to work correctly since the day I bought it. The problem I am having recently is NOTHING will apply. For example: I want to make a buy X get Y discount to apply automatically during a transaction. I set up the discount apply all the items I want to it, and edit it in the item properties, but it won't apply during the transaction. I need 2 receipts to print automatically on a sales transaction. I change that in the receipt format in Manager, but POS still won't print 2 receipts. It's very irritating, I've restarted all the programs and even r...

Outlook Vs Outlook Express #4
I am a longtime user of MS Office Suite. For my mail program I use Outlook bundled with MS Office 2002. Recently I purchased and installed McAfee's Firewall, Internet Security and Virus bundle. I have set and reset nearly all of the security settings to what I thought was an acceptable level. The first issue manifested itself by error messages indicating failure to recognize server settings etc. I called Roadrunner support and was imediately moved to Outlook Express because they do not support Outlook. Although I had to re-enter all of my contacts this worked for awhile. Now, ho...

Outlook Conector vs Hotmail Plus
Hello: What differences of operation have found between "Outlook Connector" and the service of payment "Hotmail Plus"? Testing "Outlook Connector" some times gives a message of error when I Iike to check the message, then finally, is there not problem with Hotmail Plus (that I believe that now is called "Windows Live Bonus")? -- Miguel M. Yal�n http://mmyv.com Miguel wrote: > What differences of operation have found between "Outlook Connector" and the > service of payment "Hotmail Plus"? > > Testing "Out...

execute code in worksheet_change
Dear all, I need to execute some code in worksheet_change then I did it: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$3" Then Call return_accounting_code End If If Not Intersect(Target, Range("A7:A65536")) Is Nothing Then Call return_accounting_code_description End If End Sub But it doesn't work, I think here we have like a "circular reference", because first I need to return only the accounting code (When I change the cell B3 (that contains the profit center) excel returns from access all accounting code for the profit ce...

Item number/location code does not exist in inventory error
I'm using eConnect to do an SOP transaction and it has been working for months but with a new customer and a new site I'm getting an error. The error is: "Item number/location code does not exist in inventory". The same transactions are still working with other customers on other sites so it seems like it must be a set up issue in GP. The customer and site look like they're configured the same as the ones that work so I'm stumped. Does anyone know what the issue might be? Thanks, Matt Have you confirmed that the item number has been assigned to the new sit...

Still column space after making row group hidden
In a SSRS 2008 report I have a number of parent level row groups which the previous group set the hidden value of the child group. I have the canshrink set to True of the cells however this still leaves a blank space where the group data was. Is it possible to remove this blank space from the report when that row group is hidden in a tablix? ...