Error in .Net 4.0 Assembly Load

Jul 6, 2010 at 11:11 PM
Edited Jul 6, 2010 at 11:15 PM

Hi there,

I named this discussion just like another post before, cause I get the same error, but the previous answers didn't help..

1) The export 'BoxEntryGeneratorTwo.BoxEntry2.generateEntries (ContractName="Contracts_1.IBoxEntryGenerator1")' is not assignable to type 'Contracts_1.IBoxEntryGenerator1'.


I set the Platform target to    Any    within all Dlls and here is how I compose the parts..:

            catalog = new DirectoryCatalog("plugins");
            catalog.Changed += catalog_Changed;

            var container = new CompositionContainer(catalog);

                CompositionBatch batch = new CompositionBatch();

  batch.AddPart(catalog); container.Compose(batch); ShowEntries(); } catch

Compose throws the exception.

Import is this:
        [ImportMany(typeof(IBoxEntryGenerator1), AllowRecomposition=true)]
        private IBoxEntryGenerator1[] entryGens;

And one of the Exports:

namespace BoxEntryGeneratorTwo
    public class BoxEntry2 : IBoxEntryGenerator1
        public string[] generateEntries()
            return new string[] { "House", "Hotel", "JustaString" };

Standard Mistake? Stupid Error?

Please Help



Jul 7, 2010 at 12:35 PM

I didn't see your earlier question, so please disregard my answer if it doesn't help.  Almost always when I see this kind of error, it is because two different copies of the Contracts_1 assembly are getting resolved.

1. Is Contracts_1 a signed assembly?

2. If you open the 'Modules' window, do you see more than one copy of the assembly?

3. Is the assembly installed to the GAC?  If so, is the GAC copy different than the copy that was built against?

4. Is there a stale copy of the DLL in the download cache?  (clear by using gacutil /cdl)?

These four points usually point me to the error.

Jul 7, 2010 at 4:19 PM

Hi, thanks for the answer.


1. Contracts_1 is signed (Well, it wasn't before but changing that didn't work either)

2. The assembly itself is not seen at all. Only the Project that references contract_1 an the two assemblys with the exports.

3. No its just a single testproject, why would I install it to the GAC? I hope I can avoid using the GAC.

4. I did clear it, but to no effect.

Sorry for noob questions, but is there a tutorial or simple example that I can use?

The hint about two different copies resolved seems to be it, but how do I change that? When I reference Contracs_1 in my two assemblies it gets copied to the output folder.


If you need more info or code, just tell me

thanks again

Jul 7, 2010 at 4:53 PM
I don't really have an example, this is stuff that I figured out through issues with signed assemblies over the years. You can look at the project properties for the reference and see if those have different versions or are pointing to a different location.
Jul 9, 2010 at 4:47 PM

The error in this case is because you are not exporting the correct thing:

    public class BoxEntry2 : IBoxEntryGenerator1
        public string[] generateEntries()
            return new string[] { "House", "Hotel", "JustaString" };

The Export attribute should be on the type BoxEntry2 not on the method generateEntries. The error is coming because it is trying to case the method generateEntries to type IBoxEntryGenerator1 which is not correct.



Jul 11, 2010 at 2:32 PM

OMG that was it.

rookie mistake.

Thank u all for helping!




Jul 12, 2010 at 1:48 PM
Thanks Wes, I had focused in on the error and read the exception wrong. Sorry for leading you in the wrong direction.