问题
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