我使用Kephas Framework,在创建MEF组合容器时会出现问题,如下例所示:
var ambientServicesBuilder = new AmbientServicesBuilder();
IAppManager appManager = null;
var appContext = new AppContext();
var elapsed = await Profiler.WithStopwatchAsync(
async () =>
{
await ambientServicesBuilder
.WithNLogManager()
.WithNetAppRuntime()
// the next line triggers the exception
.WithMefCompositionContainerAsync();
appManager = ambientServicesBuilder.AmbientServices.CompositionContainer.GetExport<IAppManager>();
await appManager.InitializeAppAsync(appContext);
});
似乎找不到“Kephas.Core.resources”。有什么想法吗?
答案 0 :(得分:1)
问题似乎没有出现在.NET 4.5 Framework上。下面提供了一种解决方法,请确保在初始化环境服务之前放置它:
AssemblyLoadContext.Default.Resolving += (context, name) =>
{
if (name.Name.EndsWith(".resources"))
{
return null;
}
// do other stuff, like throwing exceptions.
return null;
};
请注意,这将在运行时禁用异常,但是在设计时它仍会被抛出但不会影响程序执行。