为什么我的XmlSerializer出现错误?

我对我的工作应用程序做了一些更改,并开始在这行代码中得到以下错误。

Dim Deserializer As New Serialization.XmlSerializer(GetType(Groups)) 

这是错误。

  BindingFailure was detected Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' === Pre-bind state information === LOG: User = DOUG-VM\Doug LOG: DisplayName = FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL (Fully-specified) LOG: Appbase = file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. === LOG: This bind starts in default load context. LOG: Using application configuration file: E:\Laptop\Core Data\Data\Programming\Windows\DotNet\Work Projects\NOP\Official Apps\FUSE WPF\Fuse\bin\Debug\FUSE.vshost.exe.config LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.DLL. LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.DLL. LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.EXE. LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.EXE. 

这是怎么回事?

发生这种情况的主要原因是因为我想要序列化和反序列化的types不匹配。 我正在序列化ObservableCollection(Group)并反序列化一个业务对象 – inheritanceObservableCollection(Group)的组。

这也是问题的一部分… From – http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/9f0c169f-c45e-4898-b2c4-f72c816d4b55/

这个exception是XmlSerializer正常操作的一部分。 预计并将在框架代码中被捕获和处理。 只要忽略它,继续。 如果在debugging过程中困扰您,请将Visual Studiodebugging器设置为仅停止未处理的exception,而不是所有exception。

根据我发现的信息,与XmlSerializers关联的BindingFailureexception有时并不表示任何错误,应该只是被忽略,但有时你可以在debugging模式下看到它,当你设置VS选项来显示所有抛出的exception。

来源: https : //connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=88566&wa=wsignin1.0

顺便说一句。 这或多或less是第一个答案中提到的东西之一:)。

看来你不能find程序集FUSE.XmlSerializers。 检查程序集绑定日志查看器 (Fuslogvw.exe)的结果,看看它在哪里(尽pipe上面列出的列表看起来很满)。

尝试find这个程序集存储在您的计算机上的位置,并运行NGen ,以查看是否由于某种原因无法加载。 确保此DLL文件出现在Bin \ Debug目录中。 Visual Studio似乎没有获得依赖关系的依赖关系,所以你必须确保你有时候有自己需要的所有文件。

你是如何加载包含Groupstypes的程序集的? 我猜你用Assembly.LoadFrom()加载它,因为XML序列化程序正在使用相同的上下文('LoadFrom'上下文)试图加载程序集序列化。 如果是这样,你有几个select:

  1. 使用Assembly.Load()而不是Assembly.LoadFrom()
  2. 将一个处理程序附加到AppDomain.AssemblyResolve以帮助CLR查找有问题的程序集。

对于select的几个Visual Studio项目,我在哪里这是一个烦恼,我喜欢只禁止BindingFailureSystem.IO.FileNotFoundException的exception中断。

在Visual Studio中: Ctl + D ,“exception”对话框的Ctl + E

1)取消选中Managed Debugging Assistants下的BindingFailure

2)在Common Language Runtime Exceptions下取消选中System.IO.FileNotFoundException。

啊,这是更好的:-)

…我看到1/2这个答案是由strager给出10年11月24日在10:12

Interesting Posts