我想让SWIG与Visual Studio和C#一起工作。
我下载了swigwin-2.0.4.zip并将项目转换为VS 2010项目。
我能够构建'class'示例。当我然后尝试运行编译的构建时,我得到错误
The type initializer for 'examplePINVOKE' threw an exception.
我已经用Google搜索了错误,但没有找到任何关于如何解决错误的建议。
希望有人能够提供帮助!
谢谢,
基督教
答案 0 :(得分:3)
对我有用的是:
AnyCpu
更改为x86
并重建。不需要CorFlags。
答案 1 :(得分:1)
我在swig-user邮件列表上得到了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.
如果我能够解决问题,我会尝试这些提示并查看它们是否有效,然后发布答案。
答案 2 :(得分:1)
我的解决方案是
其中 file.exe 是通过构建代码生成的可执行文件。
有关正在发生的事情的更多信息,我们发现以下链接很有用
http://www.davesquared.net/2008/12/systembadimageformatexception-on-64-bit.html
http://blogs.msdn.com/b/joshwil/archive/2005/05/06/415191.aspx