Intermittent Error (System.TypeInitializationException: Type constructor threw an exception ) passing data to word addin from wpf app

我的未来我决定 提交于 2020-01-17 08:30:33

问题


WE have a WPF application which will launch a word and then pass some information to a VSTO Application addin.

I have written the code as has been explained here

We defined the interface and the implemtation as follows

[ComVisible(true)]
[Guid("B523844E-1A41-4118-A0F0-FDFA7BCD77C9")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IBridge {      
    /// <summary>
    /// Loads a task 
    /// </summary>      
    /// <returns> </returns>
    string Load(SomeDTO dataTransferObject);
     }

     [ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class ConcreteBridge : StandardOleMarshalObject, IBridge {
    public ConcreteBridge() { }
            public string Load(SomeDTO dataTransferObject) {
            return "some value";
            }
     }

Now I am trying to access the addin

object addInName = addinName;
COMAddIn addIn =   WordApp.COMAddIns.Item(ref addInName);
return (IBridge)addIn.Object;

The application works just fine most of the time. However , some times it throws below exception.

System.TypeInitializationException: Type constructor threw an exception. at Utilities.IBridge.Load(SomeDTO dataTransferObject)

I am not sure why this happens and would appreciate if anybody could guide me.

来源:https://stackoverflow.com/questions/8521421/intermittent-error-system-typeinitializationexception-type-constructor-threw-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!