简体   繁体   English

想要将对象类型数据从一个 VSTO 插件项目发送到另一个 VSTO 插件项目

[英]Want to Send the Object type data from one VSTO addin Project to Another VSTO addin project

I am working on a Outlook addin in which I want to send the data from one outlook addin project to another outlook project.我正在开发一个 Outlook 插件,我想将数据从一个 Outlook 插件项目发送到另一个 Outlook 项目。 But when I try call the function of another project with the object type data in the arguments it will throw "Unable to cast object of type 'System.Runtime.Remoting.Proxies.__TransparentProxy' to type at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)" error.但是,当我尝试使用参数中的对象类型数据调用另一个项目的函数时,它会抛出“无法将'System.Runtime.Remoting.Proxies.__TransparentProxy'类型的对象强制转换为System.Runtime.InteropServices.Marshal。 ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)”错误。

Here is the code for your reference.这是供您参考的代码。

                 public IProfileAttribute[] profileAttributes= null;
                 Outlook.Application outlookApp = new Outlook.Application();
                 this.profileAttributes = new FilingNotifiableIpmlementation().FilingNotification(); // to fill the object 
                object destAddinName = "Tikit.CarpeDiem.AddIn.Outlook";
                Office.COMAddIn destAddIn = outlookApp.COMAddIns.Item(ref destAddinName)                                
                destAddIn.Object.FilingNotification(this.profileAttributes);

FilingNotification() is the method which we want to call of Tikit.CarpeDiem.AddIn.Outlook this project and this.profileAttributes is the object array. FilingNotification() 是我们要调用的 Tikit.CarpeDiem.AddIn.Outlook 这个项目的方法,而 this.profileAttributes 是对象数组。

The flow is going perfectly to the Outlook project if the parameter type is either string or int but it is throwing error if the parameter is object type.如果参数类型是字符串或 int,则流程将完美地转到 Outlook 项目,但如果参数是对象类型,则会引发错误。

Implementation of FilingNotification() method in Tikit.CarpeDiem.AddIn.Outlook project. Tikit.CarpeDiem.AddIn.Outlook 项目中 FilingNotification() 方法的实现。

public void FilingNotification(IProfileAttribute[] profileAttributesList)
    {
        if (profileAttributesList != null)
        {
            var x = profileAttributesList;
        }
        else
        {
            string y = "Try again";
        }
    }

Can someone help me in this one.有人可以帮我解决这个问题。 I am stuck in this for 2 days.我被困在这两天了。 It will be really helpful.这将非常有帮助。 Thanks in advance.提前致谢。

Instead of passing a .Net object, make it implement a COM interface and pass it as an interface:与其传递一个 .Net 对象,不如让它实现一个 COM 接口并将其作为接口传递:

var obj = new MyBlah();
destAddIn.Object.FilingNotification(obj as IBlah);
...
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IBlah
{
    void DoBlah();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class MyBlah: StandardOleMarshalObject, IBlah
{
    public void DoBlah() 
    {
       //todo
    };
}

You may pass scalar data types following that way.您可以按照这种方式传递标量数据类型。 You need to implement an interface known on both sides if you want to pass objects between two entities.如果要在两个实体之间传递对象,则需要实现双方都知道的接口。 Read more about that in the Walkthrough: Call code in a VSTO Add-in from VBA article.演练:从 VBA 文章中调用 VSTO 外接程序中的代码中了解更多信息。 For example:例如:

[ComVisible(true)]
public interface IAddInUtilities
{
    void ImportData();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInUtilities : IAddInUtilities
{
    // This method tries to write a string to cell A1 in the active worksheet.
    public void ImportData()
    {
        // implementation
    }
}

Also you may consider using any standard mechanisms available for .net based applications such Remoting or WCF, see Basic WCF programming for more information.您也可以考虑使用任何可用于基于 .net 的应用程序(如 Remoting 或 WCF)的标准机制,请参阅基本 WCF 编程以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM