Can an assembly with "unsafe" methods be run from a "safe" context?
I'd like to write some optimized "unsafe" code, but provide a secondary "safe" version that can be used in sandboxes such as web pages. Is it possible to put both in the same assembly, or does the existence of any unsafe
methods prevent the assembly from being开发者_如何学Python loaded?
If I can put them both in one assembly, how do I check if it's possible to run the fast version?
And by the way, how can I run an .exe
with raised security so I can test this myself?
Tread carefully here. Assemblies containing unsafe code are marked as 'unsafe' and require full-trust in order to load and run.
Question: Is the perf boost you expect to get worth the risk of possibly exposing the underlying OS, machine, data, etc. to malware via a vulnerability in your (unsafe) code?
I would STRONGLY recommend that you carefully analyze, profile, measure and test your code - and several alternative implementations if you can - before introducing unsafe code. I've experienced few scenarios where unsafe code was truly required and when it was, have had to undergo extensive security reviews and analysis due to the potentially dangerous nature of the code.
You might want to read the following: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/596ab254-87ab-4f13-847d-4b15e9170475
精彩评论