The type initializer for '<Module>' threw an exception when try to embed Awesomium dlls

时光总嘲笑我的痴心妄想 提交于 2019-12-11 11:20:47

问题


I'm Trying to embed Awesomium into my project executable file. In the documentation of Awesomium, they said that set the target platform of your project to X86. Is that mean there is only Unmanaged32Assemblies available?

I add this line to FodyWeaver.xml file:

<Costura Unmanaged32Assemblies='Awesomium.Core|Awesomium.Windows.Forms'/>

But I got an exception that says:

System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for '<Module>' threw an exception.

I also try tried this:

<Costura 
    Unmanaged32Assemblies='Awesomium.Core|Awesomium.Windows.Forms' 
    Unmanaged64Assemblies='Awesomium.Core|Awesomium.Windows.Forms' />

But exactly same exception was thrown.

Update

Also Tried this:

<Costura 
    Unmanaged32Assemblies='awesomium' 
    Unmanaged64Assemblies='awesomium'/>

and this:

<Costura 
    Unmanaged32Assemblies='awesomium'/>

It's make my exe file about 4 MB bigger, but again same exception was thrown


回答1:


If the assembly you're trying to embed using Unmanaged32Assemblies is not a mixed-mode assembly, then that method won't work.

Instead, try adding something like this to your .csproj file:

<ItemGroup>
  <EmbeddedResource Include="..\packages\path\to\awesomium.dll">
    <LogicalName>costura32.%(Filename)%(Extension)</LogicalName>
    <Visible>false</Visible>
  </EmbeddedResource>
</ItemGroup>

Costura will find this resource at load time and extract it to a temporary directory so that your app will be able to find/load it.



来源:https://stackoverflow.com/questions/35237624/the-type-initializer-for-module-threw-an-exception-when-try-to-embed-awesomi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!