2
votes

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

1

1 Answers

2
votes

Actually I don't think this is about incompatibility between Silverlight and .NET Framework but about incompatibility between 3.5 and 4.0 .NET Framework (2.0 and 4.0 CLR).

Since you cannot reference 4.0 assemblies in 3.5 project, I presume that you may not be able to load them successfuly in a dynamic way either.


To anybody that has similar error, but not when mixing assemblies.

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

Make sure you specify StreamingContext context as parameter. I had the following method and It failed with above error:

    [OnDeserialized]
    private void OnDeserialized()
    {
        Init();
    }

Even though this question is quite old, I hope it'll help somebody.