none
Unable to find assembly exception,when perform deserialization RRS feed

  • Question

  • My winforms application has custom control, one of its property "LayoutStream" is byte[] type and it is serializable property. Currently I have ported my application from 4.6 framework to NetCore 3.0 project. 

    While run ported NetCore 3.0 project, im getting below exception when deserialize the data from resx file.

    this.control1.LayoutStream = ((SerializableByteList)(resources.GetObject("control1.LayoutStream")));

    [TypeConverter(typeof(ExpandableObjectConverter))]
            public SerializableByteList LayoutStream
    		{
                get
                {
                    return LayoutStream;
                }
                set
                {
                    LayoutStream= value;
                    if (value != null)
                        this.stmLayout.Write(value.Bytes.ToArray(), 0, value.Bytes.ToArray().Length);
                }
    		}
    
            [Serializable]
            public class SerializableByteList 
            {
                public SerializableByteList()
                {
                    Bytes = new List<byte>();
                }
                public List<byte> Bytes { get; set; }
            }

    Exception:

    Exception thrown: 'System.Runtime.Serialization.SerializationException' in System.Runtime.Serialization.Formatters.dll
    An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.Formatters.dll
    Unable to find assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    Could you please suggest any solution to resolve this issue?

     

    • Edited by Magi02 Tuesday, October 15, 2019 9:49 AM
    Tuesday, October 15, 2019 9:24 AM

All replies

  • Hello,

    See the following post for a solution to add a reference to project.json

    https://stackoverflow.com/questions/37468552/you-must-add-a-reference-to-assembly-mscorlib-version-4-0-0


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, October 15, 2019 11:49 AM
    Moderator
  • Hi Karen,

    Thanks for Reply,

    I have tried above solution, But still my issue exists. Please suggest any other solution.

    Regards,

    Magi



    Tuesday, October 15, 2019 12:28 PM
  • You should consider using the "send feedback" button in the title header of Visual Studio to see what Microsoft says.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, October 15, 2019 1:44 PM
    Moderator
  • It looks to me like there was an invalid type name in the resx file.  Can you double check this: "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

    That's listing two assembly names, separated with ]],.  Can you share the RESX that was used here?

    Tuesday, October 15, 2019 9:52 PM
  • Hi Eric

    I don't think, issue occurs due to Resx file. Please check below code is the Resx file content.

    Resx file

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <!-- 
        Microsoft ResX Schema 
        
        Version 2.0
        
        The primary goals of this format is to allow a simple XML format 
        that is mostly human readable. The generation and parsing of the 
        various data types are done through the TypeConverter classes 
        associated with the data types.
        
        Example:
        
        ... ado.net/XML headers & schema ...
        <resheader name="resmimetype">text/microsoft-resx</resheader>
        <resheader name="version">2.0</resheader>
        <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
        <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
        <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
        <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
        <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
            <value>[base64 mime encoded serialized .NET Framework object]</value>
        </data>
        <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
            <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
            <comment>This is a comment</comment>
        </data>
                    
        There are any number of "resheader" rows that contain simple 
        name/value pairs.
        
        Each data row contains a name, and value. The row also contains a 
        type or mimetype. Type corresponds to a .NET class that support 
        text/value conversion through the TypeConverter architecture. 
        Classes that don't support this are serialized and stored with the 
        mimetype set.
        
        The mimetype is used for serialized objects, and tells the 
        ResXResourceReader how to depersist the object. This is currently not 
        extensible. For a given mimetype the value must be set accordingly:
        
        Note - application/x-microsoft.net.object.binary.base64 is the format 
        that the ResXResourceWriter will generate, however the reader can 
        read any of the formats listed below.
        
        mimetype: application/x-microsoft.net.object.binary.base64
        value   : The object must be serialized with 
                : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
                : and then encoded with base64 encoding.
        
        mimetype: application/x-microsoft.net.object.soap.base64
        value   : The object must be serialized with 
                : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
                : and then encoded with base64 encoding.
    
        mimetype: application/x-microsoft.net.object.bytearray.base64
        value   : The object must be serialized into a byte array 
                : using a System.ComponentModel.TypeConverter
                : and then encoded with base64 encoding.
        -->
      <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
        <xsd:element name="root" msdata:IsDataSet="true">
          <xsd:complexType>
            <xsd:choice maxOccurs="unbounded">
              <xsd:element name="metadata">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" />
                  </xsd:sequence>
                  <xsd:attribute name="name" use="required" type="xsd:string" />
                  <xsd:attribute name="type" type="xsd:string" />
                  <xsd:attribute name="mimetype" type="xsd:string" />
                  <xsd:attribute ref="xml:space" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="assembly">
                <xsd:complexType>
                  <xsd:attribute name="alias" type="xsd:string" />
                  <xsd:attribute name="name" type="xsd:string" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="data">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                    <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
                  <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
                  <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
                  <xsd:attribute ref="xml:space" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="resheader">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" />
                </xsd:complexType>
              </xsd:element>
            </xsd:choice>
          </xsd:complexType>
        </xsd:element>
      </xsd:schema>
      <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
      </resheader>
      <resheader name="version">
        <value>2.0</value>
      </resheader>
      <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <metadata name="CustomControl1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <value>17, 17</value>
      </metadata>
      <data name="CustomControl1.LayoutStream" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>
            AAEAAAD/////AQAAAAAAAAAMAgAAAGBTeW5jZnVzaW9uLlRvb2xzLldpbmRvd3MsIFZlcnNpb249MTcu
            MzM2MC4wLjE0LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTNkNjdlZDFmODdkNDRjODkM
            AwAAAJoBbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlU
            b2tlbj1iNzdhNWM1NjE5MzRlMDg5XV0sIG1zY29ybGliLCBWZXJzaW9uPTQuMC4wLjAsIEN1bHR1cmU9
            bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OQUBAAAAQlN5bmNmdXNpb24uV2lu
            ZG93cy5Gb3Jtcy5Ub29scy5Eb2NraW5nTWFuYWdlcitTZXJpYWxpemFibGVCeXRlTGlzdAEAAAAWPEJ5
            dGVzPmtfX0JhY2tpbmdGaWVsZAQuU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tTeXN0
            ZW0uQnl0ZQMAAAACAAAACQQAAAAFBAAAAC5TeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFb
            W1N5c3RlbS5CeXRlAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24HAAACCAgDAAAACQUAAAAAAAAAAAAA
            AA8FAAAAAAAAAAIL
    </value>
      </data>
      <metadata name="panel4.Label" xml:space="preserve">
        <value>panel4</value>
      </metadata>
    </root>

    Thanks,


    • Edited by Magi02 Wednesday, October 16, 2019 3:33 AM
    Wednesday, October 16, 2019 3:32 AM
  • Exceptionthrown: 'System.Runtime.Serialization.SerializationException' in System.Runtime.Serialization.Formatters.dll
    Anunhandled exception of type 'System.Runtime.Serialization.SerializationException'occurred in System.Runtime.Serialization.Formatters.dll
    Unableto find assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Your program has a reference or a DLL your program is using has reference to mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    The DLL wanted is not in the Bin folder or wherever it needs to be like the GAC or else where, and the exception is being thrown becuase of it.

    https://www.dotnetheaven.com/article/csharp-mscorlib-assembly

    Where is the DLL based on the version number and the publickeytoken the program wants?

    https://port135.com/2018/07/06/public-key-token-assembly-dll-file/

    What was the purpose of even taking the program  to .NET Core, becuase if it's not broke, then don't fix it?

    • Edited by DA924x Wednesday, October 16, 2019 7:16 AM
    Wednesday, October 16, 2019 7:07 AM
  • Hi Team,

    Here I have attached sample application which contain both framework project and NetCore project. While run framework project it works as excepected but it fails with NetCore project.

    In the attached project, i have created custom control which has serliazable property called LayoutStream. You can able to reproduce it while run the attached NetCore project.

    Sample Link: https://drive.google.com/file/d/1WbRSuxCSQKKT5tVoH-6jY5m9t3luYRgb/view

    Here CustomControl added as assembly. Please find code for CustomControl

    Class

    [ToolboxItem(true)]
        public class Custom : Control
        {
            public Custom()
            {
                this.Size = new Size(30, 30);
                this.BackColor = Color.Red;
                LayoutStream = new CustomControl.SerializableByteList();
            }
            private CustomControl.SerializableByteList layoutStream;
            
            public CustomControl.SerializableByteList LayoutStream
            {
                get
                {
                    return layoutStream;
                }
                set
                {
                    layoutStream = value;
                }
            }
        }
    
    [Serializable]
        public class SerializableByteList
        {
            public SerializableByteList()
            {
                Bytes = new List<byte>();
            }
    
            public List<byte> Bytes { get; set; }
        }

    Screenshot:

    Please check the sample and suggest any other solution.

    Thanks,

    Wednesday, October 16, 2019 8:52 AM
  • Did you make some custom control using the non .NET Core Framework and you're trying to use it in the Core solution? If that's what you are trying to do, then I don't see this being viable for you.

    But do you understand the problem? Where is the mscorlib.dll that the program is calling for? You are being told the name of the DLL,  its version number and the publickeytoken that the program wants. That's what you have to figure out. Where is the DLL the program wants? 


    • Edited by DA924x Wednesday, October 16, 2019 11:36 AM
    Wednesday, October 16, 2019 11:23 AM
  • Hi DA924x,

    Same scenario works as expected in frmaework project without requested dll. My question is why NetCore project wants mscorlib.dll.

    Thanks,

    Wednesday, October 16, 2019 12:17 PM
  • Hi DA924x,

    Same scenario works as expected in frmaework project without requested dll. My question is why NetCore project wants mscorlib.dll.

    Thanks,

    I don't think you have done your howework before doing a porting of code.

    https://www.nuget.org/packages/Microsoft.NETCore.Portable.Compatibility/

    https://docs.microsoft.com/en-us/dotnet/standard/net-standard

    Wednesday, October 16, 2019 12:45 PM