none
Native -> mixed-mode -> XmlSerializer unable to cast same type RRS feed

  • Question

  • My program architecture has 2 variants and are as follows:

    1) Native MFC application -> native static lib -> mixed-mode DLL 1 (using lib to do early binding)
    2) .NET assembly -> mixed-mode DLL 2 -> mixed-mode DLL 1

    -----

    The mixed-mode DLL 1 has a class X with XmlRoot attribute.
    It can be serialized and deserialized using XmlSerializer properly by both architectures except under the following situations:

    1) Running NUnit, in which it complains it is unable to cast identical X to X.
    My guess is that NUnit runs in a different AppDomain somehow? I'm not too familiar.

    2) In the first architecture, if the application is a COM OCX, the cast of X to X fails as well.
    I can hack this by using static_cast instead of C style cast.

    Does anyone have any opinion?



    http://www.leowzone.com
    Monday, September 1, 2008 9:31 AM

All replies

  • Sounds like you've got the X type defined in more than one assembly.  The COM and NUnit problems then run into trouble when they load the wrong assembly.  A .NET type is bound to the assembly it is defined in.  A.X and B.X are two distinct types.  The error message is confusing because it doesn't mention the assembly identity (it doesn't say "cannot cast A.X to B.X", it says "cannot cast X to X").
    Hans Passant.
    Monday, September 1, 2008 1:02 PM
    Moderator
  • Nope, X is in just 1 of the assemblies.
    The whole namespace is the same as well.

    I suspect the problem is due the way how AppDomain is taken care of in NUnit and COM OCX.

    Anyone has other opinions?
    • Edited by kmleow Tuesday, September 2, 2008 6:19 AM Mention that namespace is the same
    Tuesday, September 2, 2008 1:11 AM