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

时间:2017-11-06 11:29:57

标签: .net-core

我使用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”。有什么想法吗?

1 个答案:

答案 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;
            };

请注意,这将在运行时禁用异常,但是在设计时它仍会被抛出但不会影响程序执行。