Assembly embedding with MEF ?

clement_911clement_911 Posts: 9
edited December 24, 2010 4:24AM in SmartAssembly 5
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

Comments

  • As I said in your other post, getting sa to work with silverlight can be a bit problematic. You'll have to exclude bits of your code to get it to work. Alex Davies also has some helpful suggestions here: http://www.red-gate.com/MessageBoard/vi ... hp?t=12271

    As ever, If in doubt get in touch with support@red-gate.com
  • The link you provided is about a different problem.

    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.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    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.
  • I see.
    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.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    I'm vaguely aware that you can have problems when you have DLL assemblies that contain nothing but type declarations. Is that how you're working as well?
Sign In or Register to comment.