Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting null from GetHostEvidence()

Tags:

c#

I'm trying to follow http://msdn.microsoft.com/en-us/library/bb763046.aspx to create a sandbox to run untrusted code.

When I execute this in my Sandboxer class:

StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();

I will get null returned. Why? How do I fix it?

like image 426
Markus Johansson Avatar asked Aug 25 '26 13:08

Markus Johansson


2 Answers

You must sign your application. The easiest way to do it is:

  1. Right click on your project in the Solution Explorer and select Properties
  2. Go to Signing tab
  3. Check Sign the assembly
  4. From drop box, select <New...>
  5. Type a name in Key file name
  6. Password is optional, so you can uncheck Protect my key file with a password
  7. Click Ok

Run the Run Partially Trusted Code in a Sandbox sample again. It should work.

like image 165
kiewic Avatar answered Aug 27 '26 04:08

kiewic


According to the page you linked, all of the calls to GetHostEvidence<T>() are being supplied with StrongName as the type parameter. If the assembly doesn't have a strong name (not all do), it will return null.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!