I am trying to deserialize layout of my UltraPictureBox.
;/Property> <Property name="Appearance"> <InstanceDescriptor member="AAEAAAD/////AQAAAAAAAAAEAQAAAC9TeXN0ZW0uUmVmbGVjdGlvbi5NZW1iZXJJbmZvU2VyaWFsaXphdGlvbkhvbGRlcgcAAAAETmFtZQxBc3NlbWJseU5hbWUJQ2xhc3NOYW1lCVNpZ25hdHVyZQpTaWduYXR1cmUyCk1lbWJlclR5cGUQR2VuZXJpY0FyZ3VtZW50cwEBAQEBAAMIDVN5c3RlbS5UeXBlW10GAgAAAAUuY3RvcgYDAAAAYkluZnJhZ2lzdGljczQuV2luLnYxNC4yLCBWZXJzaW9uPTE0LjIuMjAxNDIuMjAzNCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj03ZGQ1YzMxNjNmMmNkMGNiBgQAAAAbSW5mcmFnaXN0aWNzLldpbi5BcHBlYXJhbmNlBgUAAAAMVm9pZCAuY3RvcigpBgYAAAAHLmN0b3IoKQEAAAAKCw=="> <Property name="ImageHAlign">Center</Property> <Property name="ImageVAlign">Top</Property> </InstanceDescriptor> </Property>
When I am deserializing member attribute of InstanceDescriptor then I have an error:Could not load file or assembly 'Infragistics4.Win.v14.2, Version=14.2.20142.2034.
The error occurs for old layout which was serialized with old version v14.2. Currently we are using v16.2.I am using the following code to deserialize it:
byte[] data = Convert.FromBase64String(memberAttr.Value); BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(data); MemberInfo mi2 = (MemberInfo)formatter.Deserialize(stream);
If the layout was serialized with latest version (v16.2) then It can be deserialized.How can I deserialize member attribute of InstanceDescriptor which was serialized with old libraries?
Thanks.
Hi,
When you serialize an object, it includes the fully-qualified name of the assembly from which the classes are defined. So you can't just directly deserialize an object for which the assemblies it was serialized with are not present. In this case, when you deserialize, it's looking for the v14.2 assemblies because that's what it was serialized with.
We get around this in our control using a Binder. The BinaryFormatter has a Binder property. So you can create a binder that essentially "translates" the v14.2 assemblies into their corresponding v16.2 assemblies.
If you have access to the Infragistics source code, you could take a look at the Binder's we use for this. They all derive from a common base class:
Infragistics.Win.Serialization.Binder
In fact, you might even be able to just use that class as it is. I'm not 100% sure. It looks like that class will convert any type that is in Infragistics.Win, so it seems like it should work.
Mike,
I tried to use Binder but without success.
I tried to use as AssemblyName old version (Infragistics.Win.v14.2) and Assembly.FullName but without success.I still see the same error:System.IO.FileNotFoundException: Could not load file or assembly 'Infragistics4.Win.v14.2
var binder = new Infragistics.Win.Serialization.Binder(); binder.BindToType(typeof(Infragistics.Win.Appearance).Assembly.GetName().Name, typeof(Infragistics.Win.Appearance).FullName); formatter.Binder = binder;
You don't need to call the BindToType method. The formatter will call into this method to resolve the assembly name. So what you can do is derive a class from Infragistics.Win.Serialization.Binder and then override the BindToType method. Then you can see when that method is being called. Presumably it will be called for a v14.2 assembly and you can then translate that into the appropriate 16.2 version of the same assembly.
I have created my own Binder and I don't call BindToType method anymore. The BindToType method is invoked with parameters (assemblyName:mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, typeName). I have still gotten the same error: System.IO.FileNotFoundException: Could not load file or assembly 'Infragistics4.Win.v14.2.
public class MyBinder:Infragistics.Win.Serialization.Binder { public override Type BindToType(string assemblyName, string typeName) { return base.BindToType(assemblyName, typeName); } }
Hi Alex,
You can't just return the base. You have to get the appropriate Type in 16.2 can return it.
I'm afraid that going any further that is really beyond the scope of our support. What you are asking here really isn't related to Infragistics controls. As I mentioned, if you have access to Infragistics Source code, you could look at what that Binder and our other Binders actually do and use those as a guide. Otherwise, you need to check a more general DotNet forum for how to deal with Binders and the BindToType method.
But basically, the assemblyName and typeName here are asking for a type in v14.2 and you need to get the same type in the 16.2 assembly and return the 16.2 type.