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

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

        • <bdo id='HFqJV'></bdo><ul id='HFqJV'></ul>

        将 COM 对象添加到 Asp Net Core

        时间:2023-07-11

        <tfoot id='TMR98'></tfoot>

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

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

                <tbody id='TMR98'></tbody>
              <legend id='TMR98'><style id='TMR98'><dir id='TMR98'><q id='TMR98'></q></dir></style></legend>
                <bdo id='TMR98'></bdo><ul id='TMR98'></ul>
                  本文介绍了将 COM 对象添加到 Asp Net Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 Interop.ADODB 的单元测试项目.代码如下:

                  I have a Unit Test project that makes use of Interop.ADODB. Here is the code:

                  public CDO.Message ReadMessage(string emlFileName)
                  {
                      if (string.IsNullOrEmpty(emlFileName)) return null;
                      CDO.Message msg = new CDO.MessageClass();
                      ADODB.Stream stream = new ADODB.StreamClass();
                      stream.Open(Type.Missing,
                          ADODB.ConnectModeEnum.adModeUnknown,
                          ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, string.Empty, string.Empty);
                      stream.LoadFromFile(emlFileName);
                      stream.Flush();
                      msg.DataSource.OpenObject(stream, "_Stream");
                      msg.DataSource.Save();
                      return msg;
                  }
                  

                  问题是我将此项目转换为 .NET Core.我无法弄清楚如何导入使此方法有效所需的 COM 库.我需要的是 Interop.ADODBInterop.CDO.

                  The problem is that I converted this project to .NET Core. I cannot figure out how to import the COM libraries that I need to make this method works. The ones that I need are Interop.ADODB and Interop.CDO.

                  此方法所做的只是获取一个电子邮件文件并转换为对象,以便我可以从中读取值,然后与发送的电子邮件进行比较.真正用于验证电子邮件内容的简单单元测试.

                  All this method does is takes an email file and converts to the object so that I may read the values out of it and then compare to the email that was sent. Really a simple unit test to validate email contents.

                  有没有办法让我导入 COM 对象,或者是否有一个库可以替换我现在应该使用的 CDO.Message?

                  Is there a way for me to import COM objects or is there a library that replaced CDO.Message that I am suppose to use now?

                  推荐答案

                  不建议从 .NET Core 访问 COM 对象,因为 .NET Core 应用程序被设计为独立于平台,而 COM 对象(例如 ADODB).StreamCDO.Message 是特定于 Windows 的.

                  It's unadvisable to access COM objects from .NET Core, as .NET Core applications are designed to be platform independent, and COM objects such as ADODB.Stream and CDO.Message are specific to Windows.

                  但是,这确实是可能的 - 如果您不介意后期绑定和弱类型.

                  However, it is indeed possible - if you don't mind late binding and weak typing.

                  dynamic msg = Activator.CreateInstance(Type.GetTypeFromProgID("CDO.Message", true));
                  

                  ...

                  dynamic stream = Activator.CreateInstance(Type.GetTypeFromProgID("ADODB.Stream", true));
                  

                  等等

                  在 Windows 上运行时,这适用于 .NET Core 2.0.显然,根据这篇文章,在以前的版本中是不可能的.

                  This works on .NET Core 2.0, when running on Windows. Apparently, according to this article, it was not possible on previous versions.

                  不过,最好使用托管平台无关代码重写您的方法.

                  Still, it would be better to re-write your method using managed platform-neutral code.

                  这篇关于将 COM 对象添加到 Asp Net Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:asp net core rc2.抽象类模型绑定 下一篇:未经授权时,ASP.Net core MVC6 Redirect to Login

                  相关文章

                  1. <tfoot id='BMQmc'></tfoot>
                    <legend id='BMQmc'><style id='BMQmc'><dir id='BMQmc'><q id='BMQmc'></q></dir></style></legend>

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

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