ReflectionTypeLoadException with Silverlight serialization attributes

Posted by RPS on Stack Overflow See other posts from Stack Overflow or by RPS
Published on 2010-06-08T07:57:09Z Indexed on 2010/06/08 8:02 UTC
Read the original article Hit count: 747

Hi all,

I´m trying to inspect the types in a silverlight 4 assembly from a .NET 3.5 application. I have loaded the silverlight assembly with a Assembly.ReflectionOnlyLoadFrom sentence.

contractsAssembly = Assembly.ReflectionOnlyLoadFrom(contractsAssemblyPath);

When the .NET application tries to perform a call to GetTypes(), it throws a ReflectionTypeLoadException.

Type[] types = contractsAssembly.GetTypes();

The LoaderExceptions property in the ReflectionTypeLoadException contains a list of exceptions, all of them regarding a problem loading a type that has serialization attributes.

Type 'XXXX' in assembly 'YYYY' has method 'OnSerializing' with an incorrect signature for the serialization attribute that it is decorated with.

The type XXXX has the following definitions in it:

    [System.Runtime.Serialization.OnSerializing]
    public void OnSerializing(System.Runtime.Serialization.StreamingContext context)


    [System.Runtime.Serialization.OnSerialized]
    public void OnSerialized(System.Runtime.Serialization.StreamingContext context)


    [System.Runtime.Serialization.OnDeserializing]
    public void OnDeserializing(System.Runtime.Serialization.StreamingContext context)


    [System.Runtime.Serialization.OnDeserialized]
    public void OnDeserialized(System.Runtime.Serialization.StreamingContext context)

I have tried changing the method signature to internal or private, but with no luck. When I perform a GetTypes() call in a silverlight application that inspects this assembly I have no problems, so I thought that this was due to an incompatibility between .NET Framework and Silverlight. However, I see that .NET tools such as Reflector can inspect this Silverlight assembly, so there is a way to inspect Silverlight assemblies with serialization attributes from a .NET applciation. Could someone shed me some light on this?

Many thanks in advance.

Jose Antonio

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight