Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在VS 2010中运行SWIG C#示例_C#_Visual Studio 2010_Swig - Fatal编程技术网

无法在VS 2010中运行SWIG C#示例

无法在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

我正试图让SWIG与visualstudio和C#一起工作

我下载并将该项目转换为VS2010项目

我能够构建“类”示例。当我尝试运行编译后的构建时,我得到了错误

    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
其中file.exe是通过构建代码生成的可执行文件

关于正在发生的事情的更多信息,Í发现以下链接很有帮助


对我有效的是:

  • 转到构建->配置管理器。对于C#项目,将
    AnyCpu
    更改为
    x86
    并重建
  • 将example.dll复制到bin\x86\Debug(发行版)
    不需要CorFlags。

    记录该异常的InnerException.Seconded。通过将swig的构建配置从“x86”更改为“AnyCpu”,我还能够重新创建“type initializer”异常。恢复到“x86”,程序运行正常,没有异常。