I’ve a console application that uses MEF. It works fine locally and when deployed to a development machine. When deployed to the release machine it throws composition errors.
The development and release machine are both virtual sql server 2008 r2 machines, with the same spec and mostly the same software and components installed. There is a build and deployment process, but even copying the files from dev to release and running them results in the same error.
Are there any prerequisites I need for MEF that might be missing on the release machine, or permissions?
The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Resulting in: An exception occurred while trying to create an instance of type 'XXX.XXX.Dispatch.EmailDispatcher'.
Resulting in: Cannot activate part 'XXX.XXX.Dispatch.EmailDispatcher'.
Element: Lifetime.CrmBroker.Dispatch.EmailDispatcher --> XXX.XXX.Dispatch.EmailDispatcher --> AssemblyCatalog (Assembly="XXX.XXX, Version=1.1.2264.871, Culture=neutral, PublicKeyToken=null")
Resulting in: Cannot get export 'XXX.XXX.Dispatch.EmailDispatcher (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher")' from part 'XXX.XXX.Dispatch.EmailDispatcher'.
Element: XXXX.XXX.Dispatch.EmailDispatcher (ContractName="XXXX.XXX.Dispatch.IEntityTypeDispatcher") --> XXX.XXX.Dispatch.EmailDispatcher --> AssemblyCatalog (Assembly="XXX.XXX, Version=1.1.2264.871, Culture=neutral, PublicKeyToken=null")
Resulting in: Cannot set import 'XXX.XXXX.Dispatch.DispatcherRepository.Dispatchers (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher")' on part 'XXX.XXX.Dispatch.DispatcherRepository'.
Element: XXX.XXX.Dispatch.DispatcherRepository.Dispatchers (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher") --> XXX.XXX.Dispatch.DispatcherRepository
(System.ComponentModel.Composition.CompositionException)
Thanks for the replies guys, handy tips on debugging MEF.
It turns out that the problem was I didn’t have Entity Framework 4.1 installed on the machine. MEF was swallowing up the exception that would have been thrown, I never found it, but I did a detailed comparison between the environments and just tried installing EF 4.1 to see if it worked.