none
Casting to same type error RRS feed

  • Question

  • Hello,

    I am getting weird casting error when I de-serialize an object from a file.

    Here is the stack trace:

       System.ArgumentException: Object of type 'QAliber.TestModel.TestCase[]' cannot be converted to type 'QAliber.TestModel.TestCase[]'.
       at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
       at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck, Boolean doCheckConsistency)
       at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck)
       at System.Runtime.Serialization.FormatterServices.SerializationSetValue(MemberInfo fi, Object target, Object value)
       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.ObjectReader.Parse(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)
       at QAliber.TestModel.TestScenario.Load(String filename) in F:\Project\Qaliber Stuff\Qaliber Tool\QAliber Engine\TestModel\TestScenario.cs:line 198
       at QAliber.Builder.Presentation.TabbedScenarioControl.openToolStripButton_Click(Object sender, EventArgs e) in F:\Project\Qaliber Stuff\Qaliber Tool\QAliber Test Builder\Presentation\CustomControls\TabbedScenarioControl.cs:line 120}


    I wanted to debug through .NET source code. However, I could not find symbol files for the same.

    I am using visual studio 2008 and .NET framework 3.5

    What can be the cause of this issue?

    Thank you in advance!

    Navnath

    Friday, February 2, 2018 1:15 PM

All replies

  • A common misconception is that type A and type B are the same because they have the same type name. This is wrong. The CLR only considers 2 types to be the same if the fully qualified type names (which includes type, namespace and assembly) are the same. It appears in your case that they aren't the same type.

    You can confirm this by doing the following.

    1) Create an instance of your type directly in your code.

    2) Deserialize the value you're having an issue with into an object.

    3) Compare the types returned by GetType() on each of the objects.

    BinaryFormatter isn't a great serialization option in my opinion. It really doesn't behave well when the types are changing. But you might be able to use the AssemblyFormat and see if your problem goes away. It loosens up the type checking a little bit.


    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Fei HuModerator Wednesday, February 7, 2018 9:00 AM
    Friday, February 2, 2018 3:57 PM
    Moderator