locked
Unable to find Assembly 'dynTypeCode.dll' RRS feed

  • Question

  • I have encountered an error for which I can find no information on the web or in the MSDN documentation.

     

    The error is the following:

     

    A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

    --------- Exception Data ---------

    Message: Unable to find assembly 'dynTypeCode.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

    Exception Type: System.Runtime.Serialization.SerializationException

    Source: mscorlib

    StrackTrace:    at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()

       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)

       at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)

       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)

       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)

       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)

       at netMiroLogger.MainForm.PlaybackEventsFromLog() in C:\code\base\netMiroLogger\netMiroLogger\MainForm.cs:line 328

    TargetSite: System.Reflection.Assembly GetAssembly()

     --------------------------------------

    The code that generates the error is the following:

     

            private void PlaybackEventsFromLog()

            {

                LoggedEvents myEvent = new LoggedEvents();

                try

                {

                    while (this.isPlayingBack)

                    {

                        myEvent = (netMiroLogger.LoggedEvents)this.bfPlay.Deserialize(this.playStream);

                        this.textBoxTime.Text = myEvent.time.ToLongTimeString();

                        this.textBoxDomain.Text = myEvent.domain;

                        this.textBoxType.Text = myEvent.type;

                        this.textBoxDataPackage.Text = myEvent.dataPackage.ToString();

                    }

                }

                catch (Exception ex)

                {

                    DumpException(ex);

                    throw ex;

                }

            }

     

       [Serializable]

        public struct LoggedEvents

        {

            public int count;

            public DateTime time;

            public string domain;

            public string type;

            public object dataPackage;

     

            public LoggedEvents(StructuredEvent theEvent)

            {

                this.count = 0;

                this.time = DateTime.Now;

                this.domain = theEvent.header.fixed_header.event_type.domain_name;

                this.type = theEvent.header.fixed_header.event_type.type_name;

                this.dataPackage = theEvent.remainder_of_body;

            }

        }

     

    ------------------------------------------

    The type of object that will be contained in dataPackage is not fixed, but it will be one of some 40+ structures that are defined in referenced dll's.

     

     Any help, or a reference to where help might be found, would be appreciated.

     

    Steve.

     

    Monday, August 14, 2006 7:15 PM

Answers

  • After some further experimentation I have determined that the problem (apparently) resulted from the fact that the assemblies that contained definitions for the numerous structures that might be encountered in the dataPackage field while deserializing were not loaded - even though the assemblies where they were defined were referenced for the project in Visual Studio - by the code that serialized the objects to the Filestream.  Consequently, for some reason that probably makes perfect sense to Microsoft, the BinaryFormatter inserted references to an assembly called "dynTypeCode.dll" - rather than the actual assemblies where the objects were defined - when it encountered these unknown objects during serialization.  (The references to "dynTypeCode.dll" can be read within the binary file, and it is clear that those references ought to more correctly point to the referenced assemblies instead.)  Later, when trying to recreate the objects during deserialization it looked for the "dynTypeCode.dll" assembly to try to find the definitions.  So far as I have been able to determine, the "dynTypeCode.dll" is not actually created; in any event it could not be found by the program.

    The solution, in hindsight, is easy.

    The problem is cured by force loading the assemblies that contain the objects that might be encountered on serialization and deserialization before making calls to the BinaryFormatter.Serialize() and BinaryFormatter.Deserialize() methods using, for example, the System.Reflection.Assembly.LoadFile() method, as so:

    System.Reflection.Assembly.LoadFile(@"C:\code\base\netMIRO\InterfaceLibraries\netMiroInterfaces.dll");

    By force loading a set of several supporting assemblies, the project was able to find the definitions for the objects it needed, and it is now working correctly.

    Steve.

     

    Thursday, August 17, 2006 2:59 AM

All replies

  • Experimenting with it further, I find that it will run without raising the exception if I comment out the dataPackage field.

    Unfortunately, this makes the code pointless.

    Also, if I change the LoggedEvents struct as follows:

        [Serializable]

        public struct LoggedEvents

        {

            public int count;

            public DateTime time;

            public string domain;

            public string type;

            public netMiro.Examples.TestData dataPackage;

     

            public LoggedEvents(StructuredEvent theEvent)

            {

                this.count = 0;

                this.time = DateTime.Now;

                this.domain = theEvent.header.fixed_header.event_type.domain_name;

                this.type = theEvent.header.fixed_header.event_type.type_name;

                this.dataPackage = (netMiro.Examples.TestData)theEvent.remainder_of_body;

            }

        }

    the program works as expected.  Unfortunately, the dataPackage could be any one of a large number of objects, and in the real program one does not know which object will be used until it is encountered in the log file...

    Steve.

    Monday, August 14, 2006 9:57 PM
  • Usually, if you encounter serialization errors specific to an object, you get it because the object (or a child object within that object) is not serializable.  However that type of situation does not seem to directly be the situation here. 

    You need to start tracing backwards to see what the TestData class contains and if that DLL is a part of it.  If TestData implements ISerializable, IDeserializableCallBack then you want to see what it is doing in the Deserialize method.  For example: does Deserialize call that DLL at all?  if so you need to add it to your solution!  From the name of the dll, I would say it defines a dynamic type code in the TestData class and that being called without you being completely aware of it.  For example:

    [Serializable]

    public class TestData

    {

         string name;

         public string Name { get; }

         bool istypepresent;

         public bool IsTypePresent{get; set; }

         DynamicTypeData mydata

         public DynamicTypeData MyData {get; }

    }

    In the above example : TestData class library has included referency to dynTypeLibrary.dll to get the definition of DynaicTypeData.  You must have that DLL on your receiving side.

    Wednesday, August 16, 2006 5:03 PM
  • After some further experimentation I have determined that the problem (apparently) resulted from the fact that the assemblies that contained definitions for the numerous structures that might be encountered in the dataPackage field while deserializing were not loaded - even though the assemblies where they were defined were referenced for the project in Visual Studio - by the code that serialized the objects to the Filestream.  Consequently, for some reason that probably makes perfect sense to Microsoft, the BinaryFormatter inserted references to an assembly called "dynTypeCode.dll" - rather than the actual assemblies where the objects were defined - when it encountered these unknown objects during serialization.  (The references to "dynTypeCode.dll" can be read within the binary file, and it is clear that those references ought to more correctly point to the referenced assemblies instead.)  Later, when trying to recreate the objects during deserialization it looked for the "dynTypeCode.dll" assembly to try to find the definitions.  So far as I have been able to determine, the "dynTypeCode.dll" is not actually created; in any event it could not be found by the program.

    The solution, in hindsight, is easy.

    The problem is cured by force loading the assemblies that contain the objects that might be encountered on serialization and deserialization before making calls to the BinaryFormatter.Serialize() and BinaryFormatter.Deserialize() methods using, for example, the System.Reflection.Assembly.LoadFile() method, as so:

    System.Reflection.Assembly.LoadFile(@"C:\code\base\netMIRO\InterfaceLibraries\netMiroInterfaces.dll");

    By force loading a set of several supporting assemblies, the project was able to find the definitions for the objects it needed, and it is now working correctly.

    Steve.

     

    Thursday, August 17, 2006 2:59 AM