t3c*_*b0t 7 c# asp.net-core-mvc asp.net-core-webapi
我正在尝试使用该System.Runtime.Loader软件包将应用程序部分加载到ASP.NET Core 2.0 MVC应用程序中,但它不会让我.
错误消息说:
FileNotFoundException:无法加载文件或程序集'System.Runtime.Loader,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.
在Startup.cs我使用它像这样(它应该只是概念的证明,这是有效的,所以我可以将它移动到专门的类或扩展):
services
.AddMvc()
.ConfigureApplicationPartManager(apm =>
{
var parts = Directory.GetFiles(_rootPath, "*.Part.*");
foreach (var part in parts)
{
apm.ApplicationParts.Add(new AssemblyPart(AssemblyLoadContext.Default.LoadFromAssemblyPath(part)));
}
});
Run Code Online (Sandbox Code Playgroud)
我安装的软件包有版本4.3.0,我在带有.NET 4.6.2项目的ASP.NET Core 2.0中使用它.
我想也许装配绑定会有所帮助所以我添加了一个runtime配置app.config
<runtime>
<gcServer enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="System.Runtime.Loader" publicKeyToken="b03f5f7f11d50a3a" culture="en-US"/>
<bindingRedirect oldVersion="4.3.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
但这没有帮助.我也指定了范围,1.0.0.0-5.0.0.0但这也没有用.
IE输出的堆栈跟踪是这样的:
Run Code Online (Sandbox Code Playgroud)WebApiProject.Startup.<ConfigureServices>b__8_1(ApplicationPartManager apm) Microsoft.Extensions.DependencyInjection.MvcCoreMvcBuilderExtensions.ConfigureApplicationPartManager(IMvcBuilder builder, Action<ApplicationPartManager> setupAction) WebApiProject.Startup.ConfigureServices(IServiceCollection services) in Startup.cs - 38. public IHostingEnvironment Environment { get; } 39. 40. // This method gets called by the runtime. Use this method to add services to the container. 41. public void ConfigureServices(IServiceCollection services) 42. { 43. // Add framework services. 44. services 45. .AddMvc() ... 50. .ConfigureApplicationPartManager(apm => System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceColection services) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
在输出文件夹中有许多不同的System.Runtime.*文件,但没有一个被命名System.Runtime.Loader.也许这是问题,但这个文件在哪里?我搜索了包,但没有这样的.dll,为什么VS试图加载它?
哦,太好了.我找到了包裹.NuGet没有像往常一样将它安装到packagessoulution 的文件夹中,而是在这里:
c:\Users\%USER%\.nuget\packages\system.runtime.loader\4.3.0\lib\
Run Code Online (Sandbox Code Playgroud)
可悲的是没有版本net462.该文件夹包含一个名为的空文件:_
有几个其他文件夹,但只有一个文件夹.dll:
MonoAndroid10\
MonoTouch10\
net462\
netstandard1.5\ <-- System.Runtime.Loader.dll
xamarinios10\
xamarinmac20\
xamarintvos10\
xamarinwatchos10\
Run Code Online (Sandbox Code Playgroud)
为什么这甚至安装?我怎么可能在代码中使用类型但是*.dll即使我将它复制到输出文件夹也无法加载?这甚至应该适用于混合.net核心和旧框架的项目吗?
还有什么我可以做的吗?
请参阅 https://github.com/dotnet/corefx/issues/22142
TLDR 是 .Net Framework 不支持 System.Runtime.Loader
您将不得不使用 Assembly.Load() 代替
| 归档时间: |
|
| 查看次数: |
3670 次 |
| 最近记录: |