Не удалось загрузить файл или сборку "Microsoft.AspNetCore.Connections.Abstractions" на ASP.NET Core только на ПК с ОС Windows
Этот проект ASP.NET Core 2.1 отлично работает на моей Mac OS. Однако он вызывает это исключение, когда я запускаю его с ПК с ОС Windows. Я попытался запустить это с двух компьютеров Windows, используя ту же версию.NET Core SDK.
Я попытался переустановить.NET Core SDK 2.1.302
, также попробовал обновление до 2.1.401
. Цените любую помощь.
Ошибка
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Используемые пакеты .csproj
файле .csproj
<PackageReference Include="HangFire" Version="1.6.19" />
<PackageReference Include="Hangfire.LiteDB" Version="0.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />
<PackageReference Include="LiteDB" Version="4.1.4" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
Полная трассировка стека
> dotnet run
Using launch settings from C:\Source\repos\src\Properties\launchSettings.json...
Application startup exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance[T]()
at Microsoft.Extensions.Options.OptionsFactory'1.Create(String name)
at Microsoft.Extensions.Options.OptionsManager'1.<>c__DisplayClass5_0.<Get>b__0()
at System.Lazy'1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy'1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy'1.CreateValue()
at Microsoft.Extensions.Options.OptionsCache'1.GetOrAdd(String name, Func'1 createOptions)
at Microsoft.Extensions.Options.OptionsManager'1.Get(String name)
at Microsoft.Extensions.Options.OptionsManager'1.get_Value()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.CreateServiceContext(IOptions'1 options, ILoggerFactory loggerFactory)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions'1 options, ITransportFactory transportFactory, ILoggerFactory loggerFactory)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureServer()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
Application startup exception
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance[T]()
at Microsoft.Extensions.Options.OptionsFactory'1.Create(String name)
at Microsoft.Extensions.Options.OptionsManager'1.<>c__DisplayClass5_0.<Get>b__0()
at System.Lazy'1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy'1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy'1.CreateValue()
at Microsoft.Extensions.Options.OptionsCache'1.GetOrAdd(String name, Func'1 createOptions)
at Microsoft.Extensions.Options.OptionsManager'1.Get(String name)
at Microsoft.Extensions.Options.OptionsManager'1.get_Value()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.CreateServiceContext(IOptions'1 options, ILoggerFactory loggerFactory)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions'1 options, ITransportFactory transportFactory, ILoggerFactory loggerFactory)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureServer()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance[T]()
at Microsoft.Extensions.Options.OptionsFactory'1.Create(String name)
at Microsoft.Extensions.Options.OptionsManager'1.<>c__DisplayClass5_0.<Get>b__0()
at System.Lazy'1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy'1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy'1.CreateValue()
at Microsoft.Extensions.Options.OptionsCache'1.GetOrAdd(String name, Func'1 createOptions)
at Microsoft.Extensions.Options.OptionsManager'1.Get(String name)
at Microsoft.Extensions.Options.OptionsManager'1.get_Value()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.CreateServiceContext(IOptions'1 options, ILoggerFactory loggerFactory)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions'1 options, ITransportFactory transportFactory, ILoggerFactory loggerFactory)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureServer()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at JustALink.Program.Main(String[] args) in C:\Source\repos\src\Program.cs:line 10
Ответы
Ответ 1
Эта проблема известна в .NET Core 2.1.x, которая была исправлена в .NET Core 2.1.5 и новее. См. https://github.com/dotnet/core-setup/issues/4512.
Если после обновления .NET Core SDK вы получаете сбои из-за "System.IO.FileLoadException", вы, вероятно, сталкиваетесь с https://github.com/dotnet/core-setup/issues/4376.
Лучшим решением является обновление до .NET Core 2.1.5 или новее.
Если вы не можете обновить, другой обходной путь - обновить проект до
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.3" />
Причина этой проблемы, как описано в https://github.com/dotnet/core-setup/issues/4376, заключается в непреднамеренном обновлении общей инфраструктуры. Например:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.1" />
Microsoft.AspNetCore.All 2.1.0 зависит от Microsoft.AspNetCore.SignalR 1.0.0, но ваш проект обновлен до Microsoft.AspNetCore.SignalR 1.0.1. Когда вы dotnet publish
, вы получаете Microsoft.AspNetCore.SignalR 1.0.1 И ⚠️ его транзитивные зависимости в вашей папке публикации. Это ловушка публикации, описанная в https://natemcmaster.com/blog/2018/08/29/netcore-primitives-2/.
Это приводит к следующему
+=================+===============================+================================+============================+
| AspNetCore.All | M.A.Connections.Abstractions | M.A.Connections.Abstractions | Which M.A.C.Abstractions |
| | (in shared framework) | (in publish dir) | should load |
+=================+===============================+================================+============================+
| 2.1.0 | 2.1.0 | 2.1.1 | publish dir |
+-----------------+-------------------------------+--------------------------------+----------------------------+
| 2.1.3 | 2.1.3 | 2.1.1 | shared framework* |
+-----------------+-------------------------------+--------------------------------+----------------------------+
* Это ошибка, и https://github.com/dotnet/core-setup/issues/4512 отслеживает получение исправления в будущем обновлении 2.1.x.
Ответ 2
Я решил проблему, обновив Microsoft.AspNetCore.All
от 2.1.0
→ 2.1.3
(обновленный SDK до 2.1.401
)
Все еще не знаю, почему это работает на Mac, но не на Windows.
Ответ 3
Файл проекта основного веб-интерфейса API не содержал Microsoft.AspNetCore.All. Я вручную добавил его в группу элементов, и он исправил ее для меня.
Ответ 4
Если у вас нет Microsoft.AspNetCore.All, вы можете использовать Microsoft.AspNetCore.App и установить его версию в 2.1.3. Они совершенно одинаковы:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3"/>
Ответ 5
Вы можете добавить вручную Connection.Abstractions dll
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.1.3" />