Assembly embedding with MEF ?
clement_911
Posts: 9
Hi
I have tried the assembly embedding functionality in my Silverlight Application but it does not seem to play well with MEF.
When the code reaches "CompositionInitializer.SatisfyImports(this);", the import is failing and throws an exception.
My guess is that MEF cannot find the type because it belong into an embedded assembly, which has not been used so far.
From what I've read, the embedding feature will load the embedded assembly when it is first used. Then I guess a work around would be to force all embedded assemblies to be loaded as soon as the application starts.
Is it possible to achieve ???????
Cheers
I have tried the assembly embedding functionality in my Silverlight Application but it does not seem to play well with MEF.
When the code reaches "CompositionInitializer.SatisfyImports(this);", the import is failing and throws an exception.
My guess is that MEF cannot find the type because it belong into an embedded assembly, which has not been used so far.
From what I've read, the embedding feature will load the embedded assembly when it is first used. Then I guess a work around would be to force all embedded assemblies to be loaded as soon as the application starts.
Is it possible to achieve ???????
Cheers
Comments
As ever, If in doubt get in touch with support@red-gate.com
It would be good if it was possible to have embedded assemblies be loaded as normal dependencies rather than specially treated.
MEF and other API would then work out of the box with them.
Embedded assemblies should bind in exactly the same way as before they were embedded. I think the issue you have is with obfuscation changing the names of methods and properties. Try it without obfuscation and see if it works.
Microsoft seems to be breaking its' own rules are invoking private methods in DLLs and that is wreaking havoc with smartassembly-obfuscated methods because we assume private methods are not going to be called using Reflection. At least this is the case with Silverlight so probably with MEF as well.
Bottom line is if you are using any technology that leverages reflection, you have to do a heckuva lot of testing after you obfuscate it and you have to know the technologies you're working with at a pretty in-depth level.
As far as I know, MEF is just a library and is limited to the same silverlight rules as everyone (it's even open sourced).
I think it relies on loading all the assemblies in the manifest file. However, apparently a new manifest file is created when embedding assemblies, so that might be why MEF is not able to find the types on the dependencies.