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

发布于 2024-11-25 19:59:27 字数 406 浏览 1 评论 0原文

我正在尝试让 SWIG 与 Visual Studio 和 C# 一起使用。

我下载了 swigwin-2.0.4.zip 并将项目转换为VS 2010项目。

我能够构建“类”示例。当我尝试运行已编译的构建时,出现错误,

    The type initializer for 'examplePINVOKE' threw an exception.

我已在 google 上搜索了该错误,但没有找到有关如何解决该错误的任何建议。

希望有人能够提供帮助!

谢谢,

克里斯蒂安

I am trying to get SWIG to work with Visual Studio and C#.

I downloaded swigwin-2.0.4.zip and converted the project to a VS 2010 project.

I am able to build the 'class' example. When I then try to run compiled build I get the error

    The type initializer for 'examplePINVOKE' threw an exception.

I haved googled the error, but have not found any suggestions on how to resolve it.

Hope somebody is able to help!

Thanks,

Christian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑾夏年华 2024-12-02 19:59:27

对我有用的是:

  1. 转到“构建”->“配置管理器”。对于 C# 项目,将 AnyCpu 更改为 x86 并重建。
  2. example.dll复制到bin\x86\Debug(发布)。

不需要 CorFlags。

What worked for me was to:

  1. Go to Build->Configuration Manager. For the C# project change AnyCpu to x86 and rebuild.
  2. Copy example.dll to bin\x86\Debug (Release).

Doesn't require CorFlags.

她说她爱他 2024-12-02 19:59:27

我在 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.

我将尝试这些提示,看看它们是否有效,然后在能够解决问题时发布答案。

I got the following answer from Gregory Bronner on the swig-user mailinglist:

    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.

I will try these hints out and see whether they work and then post an answer if I am able to resolve the issue.

骄兵必败 2024-12-02 19:59:27

对我来说,解决方案是

  • 将使用的 dll 移动到发布(或调试)目录
  • 运行 CorFlags /32Bit+ file.exe

其中 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

The solution for me was

  • Move the used dll's to the Release (or Debug) directory
  • Run CorFlags /32Bit+ file.exe

where file.exe is the executable produced by building the code.

For more information on what is going on Í found the following links helpful

http://www.davesquared.net/2008/12/systembadimageformatexception-on-64-bit.html

http://blogs.msdn.com/b/joshwil/archive/2005/05/06/415191.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文