Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2006

Tip: Looking for answers? Try searching our database.

SuppressUnmanagedCodeSecurity in .NET 1.x runtime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christian Fröschlin - 01 Sep 2006 17:38 GMT
I have an assembly which calls a native method marked with the
SuppressUnmanagedCodeSecurity attribute (the security implications
of which are not the intended topic of this post). The assembly is
compiled using .NET 1.0 but intended to be used from client
applications running on arbitrary .NET runtimes.

I am fairly confident that both the usage and the P/Invoke
signature of the method is correct. In fact, everything
works fine if any of the following holds:

o The assembly is compiled in debug mode, OR
o The SuppressUnmanagedCodeSecurity attribute is omitted, OR
o The test applications runs with .NET 2.0 or Mono, OR
o A debugger is attached (argh!)

If the release version of the assembly is compiled with
the SuppressUnmanagedCodeSecurity attribute, and the test
application is started from the command line with .NET 1.0
or .NET 1.1, I get a NullReferenceException.

From test outputs in the assembly and the native DLL I know
that the problem occurs on the line where the native method
should be called, and that the code in the native method is
*not* entered. So, the error would seem to be raised from
within code of the runtime. Unfortunately, I was not able
to reproduce this with smaller test projects.

Did anyone else experience a similar behavior?
Any insights would be appreciated.
Christian Fröschlin - 04 Sep 2006 16:28 GMT
> I am fairly confident that both the usage and the P/Invoke
> signature of the method is correct.

Fairly confident obviously was not enough. The problem
turned out to be a calling convention mismatch between
StdCall and cdecl. What really surprised me though is
how far you can get without ever seeing a problem.

I suppose this means that the .NET runtime routinely uses
stack frames even for release builds, but .NET 1.x disables
them when SuppressUnmanagedCodeSecurity is used (even when
the /optimize flag is not specified when compiling).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.