We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding OldToNewDeserializationBinder for loading old versioned edp file in new version

Platform: WinForms |
Control: Diagram
Tags: diagram

Convert old versioned EDP/EDD file in new version

To overcome the problems while loading the old versioned EDP/EDD in newer version projects needs some conversion. For example if your EDP/EDD files version is 3.0 and projects version is 7.0  initially place the old versioned EDP/EDD files in the bin location of <OldToIntermediate sample> and after running the sample it will generate an EDP/EDD file of Intermediate version .

Then the Generated intermediate file must be placed in the bin location of <IntermediateToNew Sample> and after running the sample it will generate a new EDP/EDD file. It can be loaded in the newer version projects and problem won’t occurs.

Location for the Converter Sample:

C:\Users\<UserName>\AppData\Local\Syncfusion\EssentialStudio\<Installed Version>\Windows\Diagram.Windows\Samples\Converter



While using the EDD/EDP files of older version and loading in newer version it will throw Serialization exception. To avoid that exception the assembly resolver code must be used.

Add the below code snippet in your customized sample:


public void LoadPalette1(string filename)
            SymbolPalette symbolPalette = null;
            FileStream iStream;
            IFormatter formatter = new BinaryFormatter();
            ((BinaryFormatter)formatter).AssemblyFormat = FormatterAssemblyStyle.Simple;
            ((BinaryFormatter)formatter).TypeFormat = FormatterTypeStyle.TypesWhenNeeded;
            ((BinaryFormatter)formatter).FilterLevel = TypeFilterLevel.Low;
            //Assembly resolver
            formatter.Binder = new OldToNewDeserializationBinder();
            iStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
            symbolPalette = (SymbolPalette)formatter.Deserialize(iStream);



//Use the below sealed class for Assembly resolver
public sealed class OldToNewDeserializationBinder : SerializationBinder
public override Type BindToType(string assemblyName, string typeName)
            Type typeToDeserialize;
            // For each assemblyName/typeName that you want to deserialize to
            // a different type, set typeToDeserialize to the desired type.
            string assem = Assembly.GetExecutingAssembly().FullName;
            if (assemblyName.IndexOf("Syncfusion.Diagram") != -1 && assemblyName.IndexOf("Version", 0) != -1)
                // find "Version" substring
                int nIdxStart = assemblyName.IndexOf("Version", 0);
                int nIdxEnd = assemblyName.IndexOf(",", nIdxStart);
                int nIdxRplStart = assem.IndexOf("Version", 0);
                int nIdxRplEnd = assem.IndexOf(",", nIdxRplStart);
                // replace whole "Version" substring
                assemblyName = assemblyName.Replace(
                    assemblyName.Substring(nIdxStart, nIdxRplStart + (nIdxEnd - nIdxStart)),
                    assem.Substring(nIdxRplStart, nIdxRplStart + (nIdxRplEnd - nIdxRplStart)));
            if (typeName.IndexOf("LineNode") != -1)
                // types binding to ensure loading previous versions
                typeName = typeName.Replace("LineNode", "Line");
            // The following line of code returns the type.
            typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));
            return typeToDeserialize;



Public Sub LoadPalette1(ByVal filename As String)
   Dim symbolPalette As SymbolPalette = Nothing
   Dim iStream As FileStream
   Dim formatter As IFormatter = New BinaryFormatter()
   CType(formatter, BinaryFormatter).AssemblyFormat = FormatterAssemblyStyle.Simple
   CType(formatter, BinaryFormatter).TypeFormat = FormatterTypeStyle.TypesWhenNeeded
   CType(formatter, BinaryFormatter).FilterLevel = TypeFilterLevel.Low
   'Assembly resolver
   formatter.Binder = New OldToNewDeserializationBinder()
   iStream = New FileStream(filename, FileMode.Open, FileAccess.Read)
   symbolPalette = CType(formatter.Deserialize(iStream), SymbolPalette)
End Sub



Public NotInheritable Class OldToNewDeserializationBinder
 Inherits SerializationBinder
Public Overrides Function BindToType(ByVal assemblyName As String, ByVal typeName As String) As Type
   Dim typeToDeserialize As Type
   ' For each assemblyName/typeName that you want to deserialize to
   ' a different type, set typeToDeserialize to the desired type.
   Dim assem As String = System.Reflection.Assembly.GetExecutingAssembly().FullName
   If assemblyName.IndexOf("Syncfusion.Diagram") <> -1 AndAlso assemblyName.IndexOf("Version", 0) <> -1 Then
    ' find "Version" substring
    Dim nIdxStart As Integer = assemblyName.IndexOf("Version", 0)
    Dim nIdxEnd As Integer = assemblyName.IndexOf(",", nIdxStart)
    Dim nIdxRplStart As Integer = assem.IndexOf("Version", 0)
    Dim nIdxRplEnd As Integer = assem.IndexOf(",", nIdxRplStart)
    ' replace whole "Version" substring
    assemblyName = assemblyName.Replace(assemblyName.Substring(nIdxStart, nIdxRplStart + (nIdxEnd - nIdxStart)), assem.Substring(nIdxRplStart, nIdxRplStart + (nIdxRplEnd - nIdxRplStart)))
   End If
   If typeName.IndexOf("LineNode") <> -1 Then
    ' types binding to ensure loading previous versions
    typeName = typeName.Replace("LineNode", "Line")
   End If
   ' The following line of code returns the type.
   typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName))
   Return typeToDeserialize
End Function
End Class

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile