无法在VS 2010中运行SWIG C#示例
我正试图让SWIG与visualstudio和C#一起工作 我下载并将该项目转换为VS2010项目 我能够构建“类”示例。当我尝试运行编译后的构建时,我得到了错误无法在VS 2010中运行SWIG C#示例,c#,visual-studio-2010,swig,C#,Visual Studio 2010,Swig,我正试图让SWIG与visualstudio和C#一起工作 我下载并将该项目转换为VS2010项目 我能够构建“类”示例。当我尝试运行编译后的构建时,我得到了错误 The type initializer for 'examplePINVOKE' threw an exception. 我在谷歌上搜索了这个错误,但没有找到任何解决方法的建议 希望有人能帮忙 谢谢 Christian我从swig用户邮件列表上的Gregory Bronner那里得到了以下答案: I had thi
The type initializer for 'examplePINVOKE' threw an exception.
我在谷歌上搜索了这个错误,但没有找到任何解决方法的建议
希望有人能帮忙
谢谢
Christian我从swig用户邮件列表上的Gregory Bronner那里得到了以下答案:
I had this issue as well (VS2010 , Windows 7, 64 bit computer, 32 bit mode dll, .NET 4) :
The problem actually relates to being unable to load the DLLs
There were two causes:
#1: All DLLs used by the C# assembly need to be in the same directory (or you need to change the lookup paths).
#2: The C# or the C++ DLL (I forget which) had incorrect CofFlags -- use CorFlags /32Bit+ *.dll or something like that. You could also try using /UpgradeCLRHeader
#3: You need to target the .NET 4.0 system in the project file, but 1 and 2 should get you started.
我将尝试这些提示,看看它们是否有效,然后如果我能够解决问题,就发布答案。我的解决方案是
- 将使用的dll移动到发布(或调试)目录
- 运行CorFlags/32Bit+file.exe
对我有效的是:
AnyCpu
更改为x86
并重建不需要CorFlags。记录该异常的InnerException.Seconded。通过将swig的构建配置从“x86”更改为“AnyCpu”,我还能够重新创建“type initializer”异常。恢复到“x86”,程序运行正常,没有异常。