我正在尝试遵循这个答案https://stackoverflow.com/a/47295752/1237135,以获得 IIS Express 网站的列表,其中涉及引用 Microsoft.Web.dll(这是一个 .NET 程序集,但是大概它使用 COM 调用)并调用此代码
using (var runtimeStatusClient = new RuntimeStatusClient())
{
var workerProcess = runtimeStatusClient.GetWorkerProcess(19464);
//there's more but this is all that is needed for failure
}
它实际上有效,代码运行并具有有意义的数据,但是完成后几秒钟我收到此错误
System.InvalidCastException:
'Unable to cast COM object of type 'System.__ComObject'
to interface type 'Microsoft.Web.RuntimeStatus.IRsca2_WorkerProcess'.
This operation failed because the QueryInterface call on the COM component
for the interface with IID '{B1341209-7F09-4ECD-AE5F-3EE40D921870}' failed
due to the following error: No such interface supported (Exception from
HRESULT: 0x80004002 (E_NOINTERFACE)).'
E_NOINTERFACE 通常与不使用 STAThread 模型相关联,但我已经验证该线程是 STA。
该代码在控制台应用程序环境中正常运行,但在 WPF 中不运行。
上面的答案提到
我还查看了 RegisteredUrlsInfo(在 Microsoft.Web.dll 中),发现它使用了两个 COM 接口,
IRsca2_Core (F90F62AB-EE00-4E4F-8EA6-3805B6B25CDD) IRsca2_WorkerProcess (B1341209-7F09-4ECD-AE5F-3EE40D921870)
我看到另一个答案https://stackoverflow.com/a/1058978/1237135谈到
尝试将其添加到您的 App.exe.manifest:
iid="{C677308A-AC0F-427D-889A-47E5DC990138}"
proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
baseInterface="{0000000000000000000000000 -YOUR-TLB-GUID-HERE}" /> 可以从 Visual Studio 生成的 Native.Namespace.Assembly.Name.manifest 中找到 TLBID,如下所示:
但我不清楚这是否适用于此。
我还想知道它是否是 DLL Hell,但这并不能解释为什么它可以从控制台运行,是吗?
墨色风雨
相关分类