简体   繁体   中英

Assembly Exception in ASP.Net Core Angular project

I have an ASP.NET Core Angular web application. I created this project with Visual studio 2017 angular template. I made a very basic application with the newest dependencies:

  • Microsoft.AspNetCore.All (2.0.7) as NuGET
  • Microsoft.NETCore.App (2.0.0) as SDK

We can build the application but when debugging , we encounter an exception as below:

System.IO.FileLoadException HResult=0x80131040 Message=Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=Microsoft.Extensions.FileProviders.Physical

Here is the StackTrace:

StackTrace: at Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher(String root) at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options) at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors) at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at WebApp.Program.BuildWebHost(String[] args) in D:\\Source\\WebApp\\Program.cs:line 21 at WebApp.Program.Main(String[] args) in D:\\Source\\WebApp\\Program.cs:line 17

We tried going to older versions of ASP.NET Core and back. The issue solves but next time we open the project the same exception happens. We cannot change the version of the Microsoft.NETCore.App (2.0.0) to newer versions because it is blocked by the project .

Note that we have changed the location of NugetPackages to be in specific folder (D:\\Source\\Library) (for the purpose of source control).

Disable the runtime assembly specific on execution by adding the following to your project.json, under "frameworks":

"System.ComponentModel.Primitives": {
  "version": "4.1.0", // or whatever version you have
  "exclude": "runtime"
},

This is a workaround. It is happening because the platform-specific version of the System.ComponentModel.Primitives is not yet released for every platform - eg Ubuntu. More details here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM