views:

158

answers:

1

I am getting a SerializationException for an enum when calling from one AppDomain into another:

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Dummy.MyEnum,Dummy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Sample code:

public enum MyEnum
{    
  A = 0,    
  B = 1,    
  C = 2,
}

public class FooBar : MarshalByRefObject
{
  public void Test1(MyEnum dummy)
  {
  }

  public void Test2(object dummy)
  {
  }
}

This call will throw the exception:

 getFooBarInOtherAppDomain().Test1(MyEnum.A);

When using any other serializable type it succeeds:

 getFooBarInOtherAppDomain().Test2(0);

Caller, callee and enum are defined in the same assembly.

What does .Net mean with "Type is not resolved" and why is the exception thrown? Aren't enums serializable by default?

+1  A: 

Each AppDomain has its own probing path for assemblies, configured with the AppDomainSetup class. The app.config file for the primary AppDomain. It looks like in your case it is finding an assembly to load but a different one from the one that was used to serialize the data. The one it found is missing the enum type. Troubleshoot this with Fuslogvw.exe, it lets you see what assemblies are being resolved.

Hans Passant
Thanks, now I have a different problem but this helped a lot! What I don't understand is why does the Serializer want to load the assembly a second time? (the FooBar class is in the same assembly and that one is already loaded in the AppDomain, although via the primary AppDomain's probing path)
chris
Each AppDomain loads its own assemblies. Think of them as a light-weight process.
Hans Passant