应该反序列化列表<>来自 .Net 2 的工作在 .Net 4 中吗?

发布于 2024-12-01 03:54:08 字数 2189 浏览 1 评论 0 原文

从 .Net 4 应用程序到 .Net 2 应用程序进行远程调用时,我收到以下错误。

无法加载类型 System.Collections.Generic.List`1[[MyNamespace.MyClass, MyAssembly,版本=1.0.0.0,文化=中性, 反序列化需要 PublicKeyToken=null]]。

有谁知道这是否是因为 List 在 .Net 2 和 .Net 4 中不同而引起的?

此外,MyClass 有 3 个 string 和 3 个 DateTime 属性,并标记为 [Serializable] 但未实现 < code>ISerialized

这是堆栈跟踪:

服务器堆栈跟踪:
在 System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder 持有者,布尔值 bObjectFullyComplete)
在 System.Runtime.Serialization.ObjectManager.DoNewlyRegisteredObjectFixups(ObjectHolder 持有者)
在System.Runtime.Serialization.ObjectManager.RegisterObject(对象obj,Int64 objectID,SerializationInfo信息,Int64 idOfContainingObj,MemberInfo成员,Int32 [] arrayIndex)
在System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(对象obj,ParseRecord pr,ParseRecord objectPr,布尔bIsString)
在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
在System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler处理程序,__BinaryParser serParser,布尔fCheck,布尔isCrossAppDomain,IMethodCallMessage methodCallMessage)
在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流serializationStream,HeaderHandler处理程序,布尔fCheck,布尔isCrossAppDomain,IMethodCallMessage methodCallMessage)
在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流serializationStream,HeaderHandler处理程序,布尔fCheck,IMethodCallMessage methodCallMessage)
在 System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg) 重新抛出异常 在 [0]:
在 System.Activities.Statements.Throw.Execute(CodeActivityContext 上下文)
在System.Activities.CodeActivity.InternalExecute(ActivityInstance实例,ActivityExecutor执行器,BookmarkManager书签管理器)
在System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor执行器,BookmarkManager bookmarkManager,位置resultLocation)

I am getting the following error when making a remoting call from a .Net 4 Application to a .Net 2 Application.

Unable to load type
System.Collections.Generic.List`1[[MyNamespace.MyClass,
MyAssembly, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] required for deserialization.

Does anyone know if this could be caused because List<T> is different in .Net 2 and .Net 4?

Also, MyClass has 3 string and 3 DateTime properties and is marked as [Serializable] but does not implement ISerializable

Here's the Stack Trace:

Server stack trace:
at System.Runtime.Serialization.ObjectManager.CompleteObject(ObjectHolder holder, Boolean bObjectFullyComplete)
at System.Runtime.Serialization.ObjectManager.DoNewlyRegisteredObjectFixups(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj, Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo member, Int32[] arrayIndex)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
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, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg) Exception rethrown
at [0]:
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往事风中埋 2024-12-08 03:54:08

问题似乎出在加载类型上:

MyNamespace.MyClass, MyAssembly

.NET 框架需要加载 List 中的类型 T 才能序列化列表。所以问题是您的程序集或您的类型未正确加载到其他对等方中。

您应该进行工作以了解为什么抛出错误的计算机无法加载包含类型 MyNamespace.MyClass, MyAssembly 的程序集。

此外,请确保类型 MyNamespace.MyClass, MyAssembly 具有相同的版本号。

您可以使用 Fusion Log 工具查看程序集加载失败。希望有帮助。

It seems that the problem is loading your type:

MyNamespace.MyClass, MyAssembly

The .NET framework needs to load the type T in List<T> to be able to serialize the list. So the problem is that your assembly, or your type is not correctly loaded in the other peer.

You should conduct your work to understand why the machine that is throwing the error can't load the assembly that contains the type MyNamespace.MyClass, MyAssembly

Also, ensure that the type MyNamespace.MyClass, MyAssembly has the same version number.

You can see assembly load failures using the Fusion Log tool. Hope it helps.

谎言 2024-12-08 03:54:08

MyClass 正在使用 BinaryFormatter 进行序列化。请参阅http://devolutions.net/articles/dot-net /Net-Serialization-FAQ.aspx#S11

BinaryFormatter 在 .NET Framewok 版本之间进行序列化和反序列化时效果不佳。

下面详细描述了其他一些选项: .NET 中的程序集独立序列化

编辑 1 (来自评论):在 .NET 远程处理的情况下,元数据伴随着数据的编组。我假设该问题可能是由于元数据依赖于 CLR 程序集这一事实引起的,因此 List<> 中的差异非常大。 .NET 2 和 .NET 4 之间的对象可能会导致您最初假设的问题。我没有这方面的经验,但希望能有所帮助。

MyClass is being serialized using BinaryFormatter. See http://devolutions.net/articles/dot-net/Net-Serialization-FAQ.aspx#S11

BinaryFormatter does not play nice when serializing and deserializing between versions of the .NET Framewok.

Some other options are well described in the following: Assembly Independent Serialization in .NET

EDIT 1 (from comment): In the case of .NET remoting, there is metadata that goes along with the marshaling of the data. I'm assuming the issue may be caused by the fact that the metadata relies on the CLR assemblies, therefore the differences in the List<> object between .NET 2 and .NET 4 may be causing the issue which you originally assumed. I don't have experience with this, but hope that can help.

鸢与 2024-12-08 03:54:08

嗯,我尝试了一切,但没有任何效果。这是从 TFS 构建代理内启动的,因此无法进行调试。最后,我使用结果的 Xml 序列化来解决该问题。

Well, I tried everything, but nothing worked. This was launched from within a TFS Build Agent so debugging was not possible. In the end I have used Xml Serialization of the results to workaround the issue.

别理我 2024-12-08 03:54:08

我明白了,这是一篇旧文章......我只是有类似的东西:

我尝试序列化一个类,例如:

<Serializable>
Public Class MyClass
   public Property Name as String

   Private _Items as List(Of MyClass)
   Public Property Items as List(Of MyClass)
       Get ...
       Set ...
   End Property

 End Class

遇到了同样的问题。没有关于在 deseriaze 上设置 Binder 的详细信息(请参阅此处),对我来说,解决方案是将列表封装在可序列化的类中,例如:

<Serializable>
Public Class ListOfMyClass
Inherits List(Of MyClass)
Sub New()
    MyBase.New()
End Sub

Sub New(col As IEnumerable(Of MyClass))
    MyBase.New(col)
End Sub

Sub New(cap As Integer)
    MyBase.New(cap)
End Sub
End Class

最后将 MyClass 更改为:

<Serializable>
Public Class MyClass
public Property Name as String

Private Property _Items as ListOfMyClass
Public Property Items as ListOfMyClass
    Get ...
    Set ...
End Property

End Class

BR,
丹尼尔

PS:对不起 VB :)

I see, this is an old post... I just had something similar:

I tried to serialize a Class like:

<Serializable>
Public Class MyClass
   public Property Name as String

   Private _Items as List(Of MyClass)
   Public Property Items as List(Of MyClass)
       Get ...
       Set ...
   End Property

 End Class

Got the same issue. w/o Details on Setting the Binder on deseriaze (See Here) the solution for me was to encapsulate the list in a serializable class like:

<Serializable>
Public Class ListOfMyClass
Inherits List(Of MyClass)
Sub New()
    MyBase.New()
End Sub

Sub New(col As IEnumerable(Of MyClass))
    MyBase.New(col)
End Sub

Sub New(cap As Integer)
    MyBase.New(cap)
End Sub
End Class

And finally changed MyClass to:

<Serializable>
Public Class MyClass
public Property Name as String

Private Property _Items as ListOfMyClass
Public Property Items as ListOfMyClass
    Get ...
    Set ...
End Property

End Class

BR,
Daniel

PS: Sorry for VB :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文