2013-06-27 34 views
0

我有一個在我的項目中引用的COM對象。當我用目標框架4.5構建項目時,一切正常。但是,如果我將目標框架更改爲3.5(或2.0),則在嘗試使用DLLName.exe實例化類時,代碼會引發異常(我認爲它是ActiveX EXE)早期版本框架的互操作錯誤

以下是錯誤從一門外語,因此可能不準確):

System.BadImageFormatException: Could not load file or assembly 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. 
File name: 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 
.... 

Assembly loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll 
Running under file execution C:\Users\Admin\Documents\Visual Studio 2012\Projects\....t\bin\Debug\EXEname.vshost.exe 
#NAME? 
=== Pre-bind state information === 
LOG: User = 
LOG: DisplayName = Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 
(Fully-specified) 
LOG: Appbase = file:///C:/Users/Admin/Documents/Visual Studio 2012/Projects/............/bin/Debug/ 
LOG: Initial PrivatePath = NULL 
Assembly calls : EXEname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. 
=== 
.... 
LOG: Using computer file configuration from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. 
.... 
ERR: Failed to complete assembly definition (hr = 0x8013101b). 

我試圖從斌/ OBJ文件夾中刪除interop.DLLname.dll,我已籤,在構建所有項目的目標框架2.0

我失去了什麼東西?

+0

這個效果很好,當我嘗試它。在互操作庫上運行corflags.exe實用程序以進行額外檢查。 –

回答

0

是工作在這種情況下是要安裝Visual Studio 2008,並創建互操作有唯一的解決方案的鏈接。

1

因爲COM包裝DLL(interop.DLLname.dll)是爲.NET 4.5生成的,顯然它不能在早期版本的.NET用來由於不同的CLR版本您收到此錯誤。您需要獲得.net 2.0的包裝並引用它。這裏是如何生成COM包裝http://msdn.microsoft.com/en-us/library/ms404285%28v=vs.80%29.aspx

+0

據我所知,我正在做這個鏈接指示的內容。正如我在這個問題中寫的,我刪除了舊版本的互操作,並且構建了一個新的版本。爲什麼它不會生成一個與項目最小目標框架兼容的新項目?互操作框架還有另外一個設置嗎? –

+1

您需要使用Tlbimp.exe將在這裏它已經回答http://stackoverflow.com/questions/2659738/visual-studio-2010-tlbimp-generates-net-4-0-interops-in- CLR 2.0 SDK 2-0項目 –

+0

我試着在http://stackoverflow.com/questions/2659738/visual-studio-2010-tlbimp-generates-net-4-0-interops-in-2-0-projects提到的一切毫無效果爲了我。 –