3

I'm attempting to dynamically load some (purchased) assemblies from resource streams in a C# program during an MSI installation routine, but I'm getting "Unverifiable code failed policy check".

I read some tips online about compiling the embedded assembly with /clr:safe, but I don't have that option. Is there a way to work around this policy check?

Thanks.

Bevan
  • 43,618
  • 10
  • 81
  • 133
Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
  • Not an answer to your actual problem - but why hide the assemblies away in the resource stream instead of including them in the msi directly? Even if you only need them at install time, getting the msi engine to deploy them isn't too hard. – Bevan Apr 10 '10 at 04:42
  • Because I don't want them sticking around visible and in some cases it can be run post-install. – Jason Kleban Apr 10 '10 at 13:59
  • I know, this is old question.. but still want to see, if this help ? – hriziya Jun 04 '14 at 07:02

3 Answers3

4

The only way to load unverifiable code is from a full trust process (or maybe app domain) with verification disabled.

EDIT: I'm not making this up, one of the C# language designers said "Unverifiable code requires full trust and is generally to be avoided"

tomfanning
  • 9,552
  • 4
  • 50
  • 78
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Wasn't me. I would like to know too! Sounds like they would have a better suggestion. I'll counter it due to the lack of an explanation – Jason Kleban Apr 11 '10 at 20:50
3

Its already too late, but it may help someone.

I've used Sqlite DLL in my project and when I deployed the code on sandbox environment, I was getting exception (see below)

[FileLoadException: Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]

[FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.79.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]

I added trust level within system.web in the web.config file and its working fine.

<trust level="Full|High|Medium|Low|Minimal" originUrl="url"/> 
hriziya
  • 1,116
  • 1
  • 23
  • 41
  • I've long abandoned the project so I can't test, but cool! One thing - it seems that `Full|High|Medium|Low|Minimal` is redundant and that `Full` alone includes the others. (I assume this syntax is performing a bitwise `OR` on the values of the expected enum type.) – Jason Kleban Jun 04 '14 at 15:39
1

This may not be relevant any longer, but I encountered the same issue recently. If you take the stream and stick it in a temp file, you can then use Assembly.LoadFrom to load the assembly.

Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56