使用 VS 2008 Addin 出现 SerializationException:找不到程序集
我正在编写一个 Visual Studio 2008 加载项,一切工作正常,但几天后,有时会出现有关序列化的奇怪错误(无法找到程序集)。
我的插件编译工作,运行时也是如此。
打开新实例 Visual Studio 时,我的外接程序在单击菜单选项时失败。
但如果打开的解决方案全部有效(很少有时会失败)
代码:
private void AbrirFicheroMfa()
{
using (Stream containerStream = File.OpenRead(this.FicheroMFA))
{
mfaContainer = this.Deserialize(containerStream);
containerStream.Close();
}
}
public MfaContainer Deserialize(Stream serializationStream)
{
var formatter = new BinaryFormatter();
return (MfaContainer)formatter.Deserialize(serializationStream);
}
错误:
abrir Mfa 和 VisorMfa 错误:无法 寻找装配 '公司.LifeCycle.Mfa, 版本=2.0.0.0,文化=中立, PublicKeyToken=9744987c0853bf9e'。
提示: System.Runtime.Serialization.SerializationException
Mensaje:无法找到程序集 '公司.LifeCycle.Mfa, 版本=2.0.0.0,文化=中立, PublicKeyToken=9744987c0853bf9e'。
堆栈跟踪:
在 System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo,字符串名称)
在 System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(字符串 对象名称,字符串[]成员名称, BinaryTypeEnum[] binaryTypeEnumA, 对象[]类型信息A,Int32[] 成员AssemIds、对象读取器 objectReader,Int32 objectId, BinaryAssemblyInfo 程序集信息, SizedArray (assemIdToAssemblyTable)
在 System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(字符串 名称,String[] 成员名称, BinaryTypeEnum[] binaryTypeEnumA, 对象[]类型信息A,Int32[] 成员AssemIds、对象读取器 objectReader,Int32 objectId, BinaryAssemblyInfo 程序集信息, SizedArray (assemIdToAssemblyTable)
在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped 记录)
在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum 二进制标题枚举)
在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler 处理程序,__BinaryParser serParser, 布尔 fCheck,布尔 isCrossAppDomain、IMethodCallMessage 方法调用消息)
在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流 序列化流、标头处理程序 处理程序,布尔值 fCheck,布尔值 isCrossAppDomain、IMethodCallMessage 方法调用消息)位于 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流 序列化流)
在 COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.Deserialize(流 序列化流)中 E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:行 139
在 COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.AbrirFicheroMfa() 在 E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:行 131
在 COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.FrmICSharpCode_Load(对象 发送者、EventArgs e) 中 E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:line 72
有什么建议吗?
更新: 一旦我收到此错误:
SerializationException:
[A]COMPANY.LifeCycle.Mfa.MfaContainer 不能投射到 [B]COMPANY.LifeCycle.Mfa.MfaContainer。
A型起源于 '公司.LifeCycle.Mfa, 版本=2.0.0.0,文化=中立, 上下文中的 PublicKeyToken=null' 位置处的“LoadFrom” 'C:\Projects\Addins\Mfa\COMPANY.LifeCycle.Mfa.dll'。
B型源自 '公司.LifeCycle.Mfa, 版本=2.0.0.0,文化=中立, 上下文中的 PublicKeyToken=null' 位置处“LoadNeither” 'C:\Documents and Settings\eprados\Configuración local\Datos de programa\Microsoft\VisualStudio\9.0\ProjectAssemblies\wi3h64z601\COMPANY.LifeCycle.Mfa.dll'。
我有一个 WinForms 应用程序,一切正常。序列化就ok了
对于 VS Addin,我有:
Addin.dll 引用 ComunDespliegue.dll 和 LifeCycle.Mfa.dll
ComunDespliegue.dll 引用 LifeCycle.Mfa.dll
对于 WinForms 应用程序,我有:
UI.Client.dll 引用 ComunDespliegue.dll 和 LifeCycle.Mfa.dll
该程序集与我的插件一起驻留在插件目录中。我正在序列化的类型是可序列化的。 COMPANY.LifeCycle.Mfa.dll 是相同的。
I'm writing a Visual Studio 2008 add-in and all was working fine, but few days, sometimes, there are strange errors about Serialization (unable to find assembly).
My addins compile work, and runtime too.
When open new instance Visual Studio, my addin fails when click menu option.
but then if open solution all works (few sometimes fails)
code:
private void AbrirFicheroMfa()
{
using (Stream containerStream = File.OpenRead(this.FicheroMFA))
{
mfaContainer = this.Deserialize(containerStream);
containerStream.Close();
}
}
public MfaContainer Deserialize(Stream serializationStream)
{
var formatter = new BinaryFormatter();
return (MfaContainer)formatter.Deserialize(serializationStream);
}
error:
Error al abrir Mfa en VisorMfa: Unable
to find assembly
'COMPANY.LifeCycle.Mfa,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=9744987c0853bf9e'.Tipo:
System.Runtime.Serialization.SerializationExceptionMensaje: Unable to find assembly
'COMPANY.LifeCycle.Mfa,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=9744987c0853bf9e'.StackTrace:
at
System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo
assemblyInfo, String name)at
System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String
objectName, String[] memberNames,
BinaryTypeEnum[] binaryTypeEnumA,
Object[] typeInformationA, Int32[]
memberAssemIds, ObjectReader
objectReader, Int32 objectId,
BinaryAssemblyInfo assemblyInfo,
SizedArray assemIdToAssemblyTable)at
System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String
name, String[] memberNames,
BinaryTypeEnum[] binaryTypeEnumA,
Object[] typeInformationA, Int32[]
memberAssemIds, ObjectReader
objectReader, Int32 objectId,
BinaryAssemblyInfo assemblyInfo,
SizedArray assemIdToAssemblyTable)at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped
record)at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum
binaryHeaderEnum)at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser,
Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage
methodCallMessage)at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler
handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage
methodCallMessage) at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream)at
COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.Deserialize(Stream
serializationStream) in
E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:line
139at
COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.AbrirFicheroMfa()
in
E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:line
131at
COMPANY.VSIntegration.ComunDespliegue.Visualizadores.FrmVisorMfaICSharpCode.FrmICSharpCode_Load(Object
sender, EventArgs e) in
E:\TFS\pro\COMPANYTeam\Main\Public\COMPANYDevelopment\COMPANY.VSIntegration.ComunDespliegue\Visualizadores\VisorMfa\FrmVisorMfa.cs:line
72
any suggestions ?
update:
once I get this error:
SerializationException:
[A]COMPANY.LifeCycle.Mfa.MfaContainer
cannot be cast to
[B]COMPANY.LifeCycle.Mfa.MfaContainer.Type A originates from
'COMPANY.LifeCycle.Mfa,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null' in the context
'LoadFrom' at location
'C:\Projects\Addins\Mfa\COMPANY.LifeCycle.Mfa.dll'.Type B originates from
'COMPANY.LifeCycle.Mfa,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null' in the context
'LoadNeither' at location
'C:\Documents and Settings\eprados\Configuración local\Datos de programa\Microsoft\VisualStudio\9.0\ProjectAssemblies\wi3h64z601\COMPANY.LifeCycle.Mfa.dll'.
I have an WinForms application and all is work. Serialization is ok.
For VS Addin, I have:
Addin.dll references
ComunDespliegue.dll and
LifeCycle.Mfa.dllComunDespliegue.dll references
LifeCycle.Mfa.dll
For WinForms app, I have:
UI.Client.dll references
ComunDespliegue.dll and
LifeCycle.Mfa.dll
The assembly reside in the addin directory alongside my addin. the type i'm serializing is serializable. The COMPANY.LifeCycle.Mfa.dll is the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Fuslogvw.exe 找出 CLR 查找程序集的位置。有两个基本原因。首先,您在最近的更新中增加了程序集的 [AssemblyVersion],并尝试反序列化与旧版本程序集一起保存的数据。
第二个是它根本找不到DLL。只有几个地方可以存储程序集,以便在 VS 运行时可以找到它。 GAC 或 Visual Studio Common7\IDE 目录的 PrivateAssemblies 或 PublicAssemblies 子目录。
Use Fuslogvw.exe to find out where the CLR looked for the assembly. There are two basic reasons. First is that you incremented the [AssemblyVersion] of the assembly in a recent update and are trying to deserialize data that was saved with the old version of the assembly.
The second is that it simply cannot find the DLL. There are but a few places where you can store an assembly so that it can be found when VS is running. Either the GAC or the PrivateAssemblies or PublicAssemblies subdirectory of Visual Studio's Common7\IDE directory.