我在CSLA论坛上第一个asked for help,但我还没有能够解决这个问题。我创建了一个test VS2015 solution,它演示了我遇到的问题。Office 2013/2016中的C#SerializationException CSLA的VSTO加载项
我在Outlook,Word,Excel和PowerPoint中使用CSLA 4.6.603。在设置Csla.ApplicationContext.User
之后,当显示Form
或MessageBox
或甚至读取XML时,可以抛出SerializationException
。
问题的最简单的例子是:
private void MessageThrows(object sender, EventArgs e)
{
// This message displays correctly
MessageBox.Show("About to set user to UnauthenticatedPrincipal. " +
"Check Debug Output to see exception.",
"Before UnauthenticatedPrincipal");
// The user is set correctly with no exception
Csla.ApplicationContext.User = new Csla.Security.UnauthenticatedPrincipal();
try
{
// The following message throws:
// System.Runtime.Serialization.SerializationException:
// Type is not resolved for member 'Csla.Security.UnauthenticatedPrincipal,Csla,
// Version =4.6.603.0,
// Culture =neutral,
// PublicKeyToken =93be5fdc093e4c30'.
MessageBox.Show("The user has been set to UnauthenticatedPrincipal.",
"After UnauthenticatedPrincipal");
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
在测试解决方案有试图通过dataSet.ReadXml(tempFileName, XmlReadMode.InferSchema);
我处理AppDomain.CurrentDomain.AssemblyResolve
读取XML时抛出相同SerializationException
另一个例子事件和CSLA在AppDomain.CurrentDomain.GetAssemblies()
中列出,就在引发异常之前。
测试解决方案有一个非常基本的自定义标识,一个从生成的XML文件读取的基本业务对象和一个带有三个按钮的表单。
如果将WindowsUI项目设置为StartUp项目并运行它,则主窗体中的每个按钮都应成功,并且不会引发任何异常。
将WordAddIn项目设置为启动项目并运行它。 Word启动并显示与加载项加载相同的表单。第一个按钮成功,但接下来的两个按钮会引发异常。有关详细信息,请参阅调试输出或设置断点。 OutlookAddIn项目也是如此。正如其他人早些时候在CSLA论坛主题中指出的那样,这是由于.NET无法解析程序集而导致的或与之相关的。 AssemblyResolve
事件可能是答案,我只是无法弄清楚。
任何帮助将不胜感激。