2011-07-20 53 views
3

我想讓SWIG與Visual Studio和C#一起工作。無法在VS 2010中運行SWIG C#示例

我下載了swigwin-2.0.4.zip並將該項目轉換爲VS 2010項目。

我能夠建立'類'的例子。當我再嘗試運行編譯構建我的錯誤

The type initializer for 'examplePINVOKE' threw an exception. 

我haved一派錯誤,但還沒有找到如何解決它的任何建議。

希望有人能夠幫助!

感謝,

基督教

+0

記錄該異常的InnerException。 –

回答

1

我從格雷戈里布朗納在痛飲用戶郵件列表如下回答:

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. 

我會出去嘗試這些提示,看看他們是否工作,然後如果我能解決問題,請發表一個答案。

3

什麼工作對我來說是:

  1. 轉到建設 - >配置管理器。對於C#項目更改AnyCpux86並重建。
  2. 複製example.dllbin \ x86 \ Debug(Release)。

不需要CorFlags。

+0

借調。我還能夠通過將swig的構建配置從'x86'更改爲'AnyCpu'來重新創建'類型初始化程序'異常。恢復到'x86',程序運行良好,沒有例外。 。 – AndyUK