4

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)

DaveShaw
  • 52,123
  • 16
  • 112
  • 141

4 Answers4

2

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.

Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
  • Thanks for the tip. I'll have to pick this up with the developer hosting the service tomorrow as he's annoyingly left for the day. – DaveShaw Aug 23 '11 at 15:45
2

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.

Community
  • 1
  • 1
bencobb
  • 618
  • 4
  • 11
  • I've knocked together 2 simple apps to use the code from the First Link to binary serialize a List in .Net2 and deserialize in it .Net4 and it works. – DaveShaw Aug 23 '11 at 16:16
  • @DaveShaw Ok, it seems your situation may not fall under that specific issue. My experience is serializing in .net 4 and deserializing to an earlier framework I received this issue. You're going the other way, and your object may be simple enough to not cause issue. You are remoting though, so I'll add more to my answer. – bencobb Aug 23 '11 at 16:49
0

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 :)

dba
  • 1,159
  • 1
  • 14
  • 22
0

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.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141