gpt4 book ai didi

c# - 为什么在没有安装 VS.NET 的情况下 C# winforms 应用程序无法运行?

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:46 26 4
gpt4 key购买 nike

我有一个 winforms c# 应用程序,其中有一个通过 VS.NET 2008 生成的嵌入式网络浏览器控件。我们通过从 HTMLDocumentEvents2 继承我们的事件类来接收事件。

 public class IEHTMLDocumentEvents : mshtml.HTMLDocumentEvents2
{
public bool onclick(mshtml.IHTMLEventObj pEvtObj)
{
// Clicking on an input (checkbox, radio, button, image)
if (pEvtObj.srcElement.tagName == "INPUT")
{
// The following will result in a null pointer without VS.NET installed
HTMLInputElementClass input = pEvtObj.srcElement as HTMLInputElementClass;
}
}
}

在我们安装了 VS.NET 的开发机器上单击 webbrowser 控件中的元素时,上面的代码工作正常。但是,当未安装 VS.NET 时,它无法转换 pEvtObj.srcElement。当我们使用 C# 安装最基本的 VS.NET 时,这会立即开始工作。

注意:C# 应用程序的其余部分工作正常,您也可以通过控件浏览网页,只是无法正确处理上述“onclick”等事件。

我认为这将是一个 DLL 版本加载问题,但对加载的文件进行比较表明只有细微差别。

1c1
< Process: C# App without VS.NET installed
---
> Process: C# App with VS.NET 2008 installed
18d17
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\CustomMarshalers\e148983beeb0f30918b0564849a16456\CustomMarshalers.ni.dll CustomMarshalers.ni.dll Microsoft .NET Framework Custom Marshalers Microsoft Corporation 2.0.50727.3053
36d34
< C:\Documents and Settings\XpHome\Local Settings\History\History.IE5\index.dat index.dat
37a36
> C:\Documents and Settings\XpHome\Local Settings\History\History.IE5\index.dat index.dat
44,45c43,44
< C:\Program Files\<hidden>\<hidden>\Microsoft.mshtml.dll Microsoft.mshtml.dll 7.0.3300.1
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Microsoft.VisualBas#\5b3d048d8c003d743ea5e72caf07773a\Microsoft.VisualBasic.ni.dll Microsoft.VisualBasic.ni.dll Visual Basic Runtime Library Microsoft Corporation 8.0.50727.3053
---
> C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll Microsoft.mshtml.dll 7.0.3300.1
> C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualBasic\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll Microsoft.VisualBasic.dll Visual Basic Runtime Library Microsoft Corporation 8.0.50727.3053
50,52c49,51
< c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll mscorjit.dll Microsoft .NET Runtime Just-In-Time Compiler Microsoft Corporation 2.0.50727.3053
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\9adb89fa22fd5b4ce433b5aca7fb1b07\mscorlib.ni.dll mscorlib.ni.dll Microsoft Common Language Runtime Class Library Microsoft Corporation 2.0.50727.3053
< c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll mscorwks.dll Microsoft .NET Runtime Common Language Runtime - WorkStation Microsoft Corporation 2.0.50727.3053
---
> c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll mscorjit.dll Microsoft .NET Runtime Just-In-Time Compiler Microsoft Corporation 2.0.50727.3082
> C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\7124a40b9998f7b63c86bd1a2125ce26\mscorlib.ni.dll mscorlib.ni.dll Microsoft Common Language Runtime Class Library Microsoft Corporation 2.0.50727.3603
> c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll mscorwks.dll Microsoft .NET Runtime Common Language Runtime - WorkStation Microsoft Corporation 2.0.50727.3603
94,98c93,97
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\cb4cb21d14767292e079366a5d3d76cd\System.Configuration.ni.dll System.Configuration.ni.dll System.Configuration.dll Microsoft Corporation 2.0.50727.3053
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\6978f2e90f13bc720d57fa6895c911e2\System.Drawing.ni.dll System.Drawing.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\aa7926460a336408c8041330ad90929d\System.ni.dll System.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\9a254c455892c02355ab0ab0f0727c5b\System.Windows.Forms.ni.dll System.Windows.Forms.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
< C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\36f3953f24d4f0b767bf172331ad6f3e\System.Xml.ni.dll System.Xml.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
---
> C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll System.Configuration.dll System.Configuration.dll Microsoft Corporation 2.0.50727.3053
> C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\abb2ac7e08bee026f857d8fa36f9fe6f\System.Drawing.ni.dll System.Drawing.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
> C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\3de5bd01124463d7862bd173af90bc83\System.ni.dll System.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
> C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\d2ea8d76f015817db1607075812b555f\System.Windows.Forms.ni.dll System.Windows.Forms.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3053
> C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\5913d3f81e77194ec833991b1047a532\System.Xml.ni.dll System.Xml.ni.dll .NET Framework Microsoft Corporation 2.0.50727.3082

最佳答案

好的,终于找到答案了。似乎即使它成功加载了我们随应用程序分发的 microsoft.mshtml.dll。除非您使用 regasm.exe 在客户端机器上的 GAC 中注册,否则无法访问 COM 接口(interface)。

关于c# - 为什么在没有安装 VS.NET 的情况下 C# winforms 应用程序无法运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2970291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com