<bdo id='RYta3'></bdo><ul id='RYta3'></ul>

      <legend id='RYta3'><style id='RYta3'><dir id='RYta3'><q id='RYta3'></q></dir></style></legend>
    1. <tfoot id='RYta3'></tfoot>
    2. <small id='RYta3'></small><noframes id='RYta3'>

      <i id='RYta3'><tr id='RYta3'><dt id='RYta3'><q id='RYta3'><span id='RYta3'><b id='RYta3'><form id='RYta3'><ins id='RYta3'></ins><ul id='RYta3'></ul><sub id='RYta3'></sub></form><legend id='RYta3'></legend><bdo id='RYta3'><pre id='RYta3'><center id='RYta3'></center></pre></bdo></b><th id='RYta3'></th></span></q></dt></tr></i><div id='RYta3'><tfoot id='RYta3'></tfoot><dl id='RYta3'><fieldset id='RYta3'></fieldset></dl></div>

        COM 互操作对象在一个项目中引发 InvalidCastException,但在其他项目中不引发

        时间:2023-07-24

        • <bdo id='Lyo9i'></bdo><ul id='Lyo9i'></ul>
            <tbody id='Lyo9i'></tbody>
          <tfoot id='Lyo9i'></tfoot>
            <legend id='Lyo9i'><style id='Lyo9i'><dir id='Lyo9i'><q id='Lyo9i'></q></dir></style></legend>

              <small id='Lyo9i'></small><noframes id='Lyo9i'>

                  <i id='Lyo9i'><tr id='Lyo9i'><dt id='Lyo9i'><q id='Lyo9i'><span id='Lyo9i'><b id='Lyo9i'><form id='Lyo9i'><ins id='Lyo9i'></ins><ul id='Lyo9i'></ul><sub id='Lyo9i'></sub></form><legend id='Lyo9i'></legend><bdo id='Lyo9i'><pre id='Lyo9i'><center id='Lyo9i'></center></pre></bdo></b><th id='Lyo9i'></th></span></q></dt></tr></i><div id='Lyo9i'><tfoot id='Lyo9i'></tfoot><dl id='Lyo9i'><fieldset id='Lyo9i'></fieldset></dl></div>
                1. 本文介绍了COM 互操作对象在一个项目中引发 InvalidCastException,但在其他项目中不引发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的测试 C# 解决方案中导入了一个 COM 对象.一切正常,并继续这样做.

                  I have a COM object I imported in my test C# solution. Everything works fine and continues to do so.

                  然后我在我的实际解决方案中导入了相同的 COM 对象,并作为测试实现了与测试项目中完全相同的行.
                  当我运行真正的项目时,我得到一个 InvalidCastException

                  Then I imported the same COM object in my actual solution and as a test implemented the exact same lines as in the test project.
                  When I run the real project I get an InvalidCastException

                  无法将CTWebReport.WebReportCOMClass"类型的 COM 对象转换为接口类型CTWebReport.IWebReportCOM".此操作失败,因为 IID 为{5DFA18E8-4E71-4ADC-A812-6B166C242561}"的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)).

                  我在整个系统中搜索了对 interop 和 com 库的每个引用,这包括我能找到的所有 bin 和 obj 文件夹.除了原来的 COM 库,我将它们全部删除,并清理了我的回收站.
                  没有区别,完全一样的情况.测试项目有效,实际项目无效.

                  I searched my entire system for every reference to the interop and com library, this includes all the bin and obj folders I could find. Except for the original COM library I deleted them all and for good measure cleaned out my recycle bin.
                  No difference, exact same situation. Test project works, real project doesn't.

                  编辑
                  似乎 COM 在 winforms 应用程序中工作,但在我的类库中不起作用(由 asp.net mvc web applicatoin 使用).

                  EDIT
                  It seems that the COM works in winforms applications, but not in my class librar (that is consumed by an asp.net mvc web applicatoin).

                  我不知道下一步该做什么.有什么建议吗?

                  I don't know what to do next. Suggestions?

                  推荐答案

                  不同之处在于线程.winform 线程从主线程执行代码,而 asp.net 没有.它是通过在 STAThread 中显式运行 COM 来解决的.

                  The difference was in threading. The winform thread executed the code from the main thread, whereas the asp.net didn't. It was solved by explicitly running the COM in a STAThread.

                  这篇关于COM 互操作对象在一个项目中引发 InvalidCastException,但在其他项目中不引发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为 COM 互操作性注册我的 .net 程序集不会公开我的方法 下一篇:有没有更好的方法(除了COM)来远程控制Excel?

                  相关文章

                2. <tfoot id='NhqRi'></tfoot>

                      <bdo id='NhqRi'></bdo><ul id='NhqRi'></ul>

                  1. <small id='NhqRi'></small><noframes id='NhqRi'>

                    1. <legend id='NhqRi'><style id='NhqRi'><dir id='NhqRi'><q id='NhqRi'></q></dir></style></legend>
                      <i id='NhqRi'><tr id='NhqRi'><dt id='NhqRi'><q id='NhqRi'><span id='NhqRi'><b id='NhqRi'><form id='NhqRi'><ins id='NhqRi'></ins><ul id='NhqRi'></ul><sub id='NhqRi'></sub></form><legend id='NhqRi'></legend><bdo id='NhqRi'><pre id='NhqRi'><center id='NhqRi'></center></pre></bdo></b><th id='NhqRi'></th></span></q></dt></tr></i><div id='NhqRi'><tfoot id='NhqRi'></tfoot><dl id='NhqRi'><fieldset id='NhqRi'></fieldset></dl></div>