Tag: comobject

使用带有__ComObject的“dynamic”关键字时,在RuntimeBinder中泄漏

当在C#中使用带有__ComObject实例的“dynamic”关键字时,有没有人知道是否有办法防止RuntimeBinder中的内存泄漏? 我得到以下代码: var t = Type.GetTypeFromCLSID(new Guid(“BB06C0E4-D293-4f75-8A90-CB05B6477EEE”)); while (true) { dynamic o = System.Activator.CreateInstance(t); Marshal.ReleaseComObject(o); } 这会泄漏LocalVariableSymbol类实例(以及Microsoft.CSharp.RuntimeBinder.Semantics命名空间中的其他实例)。 用“对象”替换“动态”即: object o = System.Activator.CreateInstance(t); 修复泄漏,但我更喜欢继续使用动态(实际代码更复杂,并使用“动态”)。 我知道RuntimeBinder单例缓存数据,这会导致泄漏,但你知道是否有任何方法来清理缓存等? 非常感谢! 类似的问题: 内存溢出:拥有越来越多的Microsoft.CSharp.RuntimeBinder.Semantics CLR类中的内存泄漏 相关链接: https://connect.microsoft.com/VisualStudio/feedback/details/1925659 (由微软退休) https://github.com/dotnet/roslyn/issues/2887

MSHTML HTMLHeadElementClass COM错误

我目前正在使用MS HTML将JavaScript代码插入到网站中。 我引用了Microsoft HTML Object Library并输入了这段代码。 IHTMLDocument2 doc = BrowserHost.Document as HTMLDocumentClass; IHTMLElement head = (IHTMLElement) ((IHTMLElementCollection)doc.all.tags(“head”)).item(null, 0); IHTMLScriptElement scriptObject = (IHTMLScriptElement)doc.createElement(“script”); scriptObject.type = @”text/javascript”; scriptObject.text = TTS.TTSWebFactory.GetJavascript(); ((HTMLHeadElementClass)head).appendChild((IHTMLDOMNode)scriptObject); 我在脚本的最后一行收到错误,这是消息。 Unable to cast COM object of type ‘System._ComObject’ to class type ‘mshtml.HTMLHeadElementClass’. COM components that enter the CLR and do not support IProvideClassInfo or that […]

如何从webbrowser控件获取onclick中的实际JavaScript值?

我正在寻找一种方法来获取onclick中定义的JavaScript代码。 我正在使用.NET 2.0 C#Visual Studio 2005。 例: click here 我的目标是获取字符串“window.location.href =’someURL’” 。 场景: 用户点击Web页面元素,例如上面显示的标签,在WebBrowser控件内部。 然后将单击的标记tmlElement object到H tmlElement object 。 在WebBrowser控件中我然后调用HtmlElement object’s getAttribute(“onclick”) ,它只给我“ System .__ ComObject”。 我已经搜索了如何处理它然后发现它可以被铸造然后获得价值。 if (tag.GetAttribute(“onclick”).Equals(“System.__ComObject”)) { Console.WriteLine(“dom elem >>>>>>>>>>> ” + tag.DomElement.ToString()); mshtml.HTMLSpanElementClass span = (mshtml.HTMLSpanElementClass)tag.DomElement; Console.WriteLine(“js value ===>” + span.onclick); } 输出: dom elem >>>>>>>>>>> mshtml.HTMLSpanElementClass js value ===> System.__ComObject […]

如何在C#中的System.Type中返回System .__ COMObject的类型

我正在做一个程序,我想做一个reflection,但为此,我需要一个Type of Type类,对吧? 使用.GetProperties()方法……所以我尝试了这个: Type typeName = simObjects.getType(); 但.GetType()返回“System .__ COMObject”。 这没有用。 .typeof()也是如此。 我搜索并找到了另一个代码,这个代码: Type typeName = (Type)Microsoft.VisualBasic.Information.TypeName(simObjects); 但是这个方法返回一个String,我需要它在System.Type中,任何天才请帮帮我吗?