.net core 我得到System.IO.FileNotFoundException:';无法加载指定的文件。';在.NET Core上创建合成容器时

.net core 我得到System.IO.FileNotFoundException:';无法加载指定的文件。';在.NET Core上创建合成容器时,.net-core,.net Core,我使用Kephas框架,在创建MEF合成容器时会出现问题,如下例所示: var ambientServicesBuilder = new AmbientServicesBuilder(); IAppManager appManager = null; var appContext = new AppContext(); var elapsed = await Profiler.WithStopwatchAsync(

我使用Kephas框架,在创建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);
                });
var-ambientServicesBuilder=new-ambientServicesBuilder();
IAppManager-appManager=null;
var appContext=new appContext();
var已用=等待探查器。WithStopwatchAsync(
异步()=>
{
等待环境服务构建器
.WithNLogManager()
.WithNetAppRuntime()
//下一行触发异常
.WithMefCompositionContainerAsync();
appManager=ambientServicesBuilder.AmbientServices.CompositionContainer.GetExport();
等待appManager.InitializeAppAsync(appContext);
});

似乎找不到“Kephas.Core.resources”。有什么想法吗?

这个问题似乎没有出现在.NET 4.5框架上。下面提供了一个解决方法,请确保在初始化环境服务之前放置它:

        AssemblyLoadContext.Default.Resolving += (context, name) =>
            {
                if (name.Name.EndsWith(".resources"))
                {
                    return null;
                }

                // do other stuff, like throwing exceptions.
                return null;
            };
请注意,这将在运行时禁用异常,但在设计时仍会抛出异常,但不会影响程序执行