Assembly.LoadFile () throws an exception due to lack of manifest

The exception is:

The module is expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)

I get it on the line:

Assembly lvAssembly = Assembly.LoadFile(aPathFileName); 

The download file is a plugin created by another application. If I changed the version of the Framework Framework plugin from 4.0 to 3.5 and recompiled. The plugin loads fine. I don’t understand why the Assembly.LoadFile method took care of which version of the .net structure to compile the plugin.

Changing the target platform for the application loading the plugin in 4.0 did not help.

+4
source share
1 answer

The first part of your question is the expected result, version 2 of the CLR cannot load .NET 4.0 assemblies, the metadata format has changed.

The last paragraph is more difficult to explain. This may have something to do with using LoadFile (), this is a plugin way to load assemblies. One possible failure mode is that your plug-in assembly may have links to assemblies 2.0. This is pretty normal when it has a link to another assembly that was compiled to target an earlier structure. Usually this is normally resolved by the collector, it simply replaces the link 2.0 with a link to the corresponding 4.0.

You can test this theory with ildasm.exe, run it on the plug-in, and view the manifest for .assembly directives. The version number is easy to see, you will get something like

 .assembly extern mscorlib as mscorlib_2 { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 2:0:0:0 } 

Always welcome Assembly.LoadFrom ().

+6
source

Source: https://habr.com/ru/post/1335272/


All Articles