為什麼我可以從在 IIS7 中以 64 位模式運行的 AnyCPU .NET Web 應用程序調用 32 位 COM 庫? (Why am I able to call a 32 bit COM library from an AnyCPU .NET web application running in IIS7 in 64 bit mode?)


問題描述

為什麼我可以從在 IIS7 中以 64 位模式運行的 AnyCPU .NET Web 應用程序調用 32 位 COM 庫? (Why am I able to call a 32 bit COM library from an AnyCPU .NET web application running in IIS7 in 64 bit mode?)

Without using a COM+ proxy service, I'm quite happily able to use classes from a 32 bit COM interop library from a .NET application compiled with target AnyCPU, running in a 64 bit w3wp process.

I'm successfully instantiating classes from a 32 bit COM interop library in a 64 bit .NET process.

w3wp is running in 64 bit mode, and the IIS configuration is set to not allow 32 bit applications. Ontop of that is the fact that there's a specifically x64 compiled and registered .NET assembly down the line.

I'm just wondering, how is this at all possible?

Of interest is that this works just beautifully if the code is compiled with Visual Studio 2008, targeting the 3.5 framework. If the same code is compiled with Visual Studio 2010, targeting the 3.5 framework, the application fails spectacularly when it tries to load the 32 bit COM interop library. As it should.


參考解法

方法 1:

It will be running in 32-bit mode if it is running at all, you cannot have 32bit stuff in a 64bit process and vice versa.  A process is entirely one or the other.

That is not the same as running a 32bit process on a 64bit host, obviously, that works.

The other alternative is that the third party stuff is actually providing a 64bit reference, and your conclusion of it running 32bit is incorrect.

方法 2:

You. Are. Not.

Point.

Put the web application to 32 bit mode. This is actually how they SHOULD run per MS IIS guidelines (that most people never bother to read).

方法 3:

The w3wp process can run in 32-bit mode and thus can handle 32bit assemblies. See whether your IIS service is running in 32-bit mode.

方法 4:

I'll chalk this up to some complexity in the tonnes of code and projects that the solution consists of. Removing the requirements of the offending library to be 64 bits has solved the issue, but naturally doesn't answer the question. It just makes it obsolete.

方法 5:

It works through the DllSurrogate mechanism which automatically creates a DllHost process when you try to load a com-dll of the wrong bitness. In those cases you get implicit interprocess communication. Just take a look at main.

(by J. SteenAdam HouldsworthTomTomKangkanJ. Steentobias.loew)

參考文件

  1. Why am I able to call a 32 bit COM library from an AnyCPU .NET web application running in IIS7 in 64 bit mode? (CC BY-SA 3.0/4.0)

#ASP.NET #32bit-64bit #iis-7 #com #C#






相關問題

System.Reflection.Assembly.LoadFile 鎖定文件 (System.Reflection.Assembly.LoadFile Locks File)

如何在沒有全局變量的情況下一直保留我的變量? (How can I keep my variable all the time without global variables?)

C# / ASP.NET - Web 應用程序鎖定 (C# / ASP.NET - Web Application locking)

關閉模態對話框窗口後 ASP.NET 刷新父頁面 (ASP.NET Refresh Parent Page after Closing Modal Dialog Window)

無法將 NULL 值傳遞給數據庫 (Unable to pass NULL value to database)

wcf:將用戶名添加到消息頭是否安全? (wcf: adding username to the message header is this secure?)

使用 ASP.Net 教初學者 Web 開發的小項目想法 (Small projects ideas to teach beginners web development using ASP.Net)

SQL Server - 分組、擁有和計數 (SQL Server - Group by, having and count in a mix)

企業庫異常處理應用程序塊和日誌記錄應用程序塊在 ASP.NET 中的正確使用 (Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET)

來自proc的asp.net多個結果集:是否有必要將結果映射到類?如果是這樣,怎麼做? (asp.net multiple result set from proc: is it necessary to map results to class? If so, how?)

如何在測試工具中實例化 asp.net 代碼隱藏類? (How can I instantiate an asp.net codebehind class in a test harness?)

Web 窗體用戶控制事件,需要在頁面加載後添加 (Web Form User Control Event, needs to be added after page loads)







留言討論