1. 程式人生 > >(c# 呼叫c++dll)an unhandled exception of type 'system.runtime.interopservices.comexception'

(c# 呼叫c++dll)an unhandled exception of type 'system.runtime.interopservices.comexception'

問題發生場景:

    win10 64bit作業系統,vs2008

    c++開發的dll檔案,c#建立WindowsFormsApplication或者ConsoleApplication

    託管方式呼叫c++dll檔案,通過新增引用->COM,選擇以及註冊的dll檔案

    c#程式碼中增加如下程式碼

        MyFun  myfun = new MyFun();

        myfun.test();


    在執行到new的時候就提示如題的錯誤


解決方法:

c#工程中,右鍵->屬性,更改platform target為X86,重新編譯後呼叫成功