.net MEF合成错误:仅在某些机器上

.net MEF合成错误:仅在某些机器上,.net,components,mef,composition,.net,Components,Mef,Composition,我有一个使用MEF的控制台应用程序。它在本地和部署到开发机器时都可以正常工作。当部署到发布机器时,它抛出组合错误 开发和发布机器都是虚拟的sql server 2008 r2机器,具有相同的规范,安装的软件和组件基本相同。有一个构建和部署过程,但即使将文件从dev复制到release并运行它们,也会导致相同的错误 发布计算机上是否缺少MEF所需的任何先决条件或权限 The composition produced a single composition error. The root caus

我有一个使用MEF的控制台应用程序。它在本地和部署到开发机器时都可以正常工作。当部署到发布机器时,它抛出组合错误

开发和发布机器都是虚拟的sql server 2008 r2机器,具有相同的规范,安装的软件和组件基本相同。有一个构建和部署过程,但即使将文件从dev复制到release并运行它们,也会导致相同的错误

发布计算机上是否缺少MEF所需的任何先决条件或权限

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)

检查动态加载类型的构造函数。MEF将构造器中的问题隐藏在MEF错误后面,这些错误没有帮助。确保构造函数中有错误处理,然后添加一些日志以捕获“真实”异常。

检查动态加载类型的构造函数。MEF将构造器中的问题隐藏在MEF错误后面,这些错误没有帮助。确保构造函数中有错误处理,然后添加一些日志以捕获“真实”异常。

添加一些代码以捕获
CompositionException
并获取有关 根本原因如下:

catch (CompositionException e)
{
    // "unable to load one or more of the requested types" hints at a
    // ReflectionTypeLoadException, so cast to that
    var loadException = (ReflectionTypeLoadException)e.Errors.First(); 

    // as the error said,
    // "Retrieve the LoaderExceptions property for more information"
    var cause = loadException.LoaderExceptions.First();

    // print, log or extract the information in some other way 
    Debug.Print(cause.Message);
}

不过,它似乎只是缺少依赖项。

添加一些代码以捕获
组合异常并获取有关
根本原因如下:

catch (CompositionException e)
{
    // "unable to load one or more of the requested types" hints at a
    // ReflectionTypeLoadException, so cast to that
    var loadException = (ReflectionTypeLoadException)e.Errors.First(); 

    // as the error said,
    // "Retrieve the LoaderExceptions property for more information"
    var cause = loadException.LoaderExceptions.First();

    // print, log or extract the information in some other way 
    Debug.Print(cause.Message);
}

不过,这似乎只是一个缺少的依赖项。

感谢各位的回复,关于调试MEF的便捷提示


问题是我没有在机器上安装EntityFramework4.1。MEF正在吞噬可能抛出的异常,我从未找到它,但我在环境之间做了详细的比较,并尝试安装EF 4.1以查看它是否有效。

感谢各位的回复,关于调试MEF的便捷提示

问题是我没有在机器上安装EntityFramework4.1。MEF正在吞咽可能抛出的异常,我从未找到它,但我在环境之间做了详细的比较,只是尝试安装EF4.1,看看它是否有效