MEF with PostSharp

Jan 9, 2013 at 4:01 PM

Hi,

I'm having a problem using PostSharp and MEF together. I have a MEF export that has a reference to an Assembly that is process by PostSharp. When I try to run the application I got an exception trying to load the assembly that is processed by PostSharp. If I disable PostSharp everything works fine. I try to use the FusionLogViewer but the only thing that I see that could help explain the error is that when using PostSharp I get this line on the log: "LOG: This bind starts in default load context." while with PostSharp disabled I get this line "LOG: This bind starts in LoadFrom load context.".

I have the extension assembly and its references in a sub folder of the application.

 

Any help would be appreciated,

Thanks in advance,

Nuno Pereira

Jan 23, 2013 at 4:31 PM

Hi,

I’ve received a response from SharpCrafters support forum that give me a better understanding of what was happening.

As far as I understand MEF loads the assemblies into the LoadFrom binding context and PostSharp looks for the assemblies in the default Load binding context.

I was able to make the error disappear by handling the AppDomain.AssemblyResolve event and look for the assembly in AppDomain.CurrentDomain.GetAssemblies() because the assembly is already loaded, but in a different context.

My question now is why are assemblies loaded by MEF loaded into the LoadFrom context? What side effects can this solution have? Will I have problems if two different MEF extensions have dependencies to different versions of the same assembly by using the default Load context?

Thanks for the help,

Nuno Pereira