9
votes

I'm building aspnet core app. I wanted to keep one of my MVC Controllers in Class Library (so outside main project).

In order to do that, I've created new class extending Controller in Class Library project called "DataSync". Then, I referenced it in Startup.cs file of main project:

services.AddMvc().AddApplicationPart(Assembly.Load(new AssemblyName("DataSync")));

Here is the error that I see when I try to open main project in browser:

TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.Internal.IHttpResponseStreamWriterFactory' from assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Where should I look for possible problems? What could go wrong here?

5

5 Answers

4
votes

I encountered this when I added a new Nuget package (Microsoft.AspNetCore.Mvc.Versioning) which had a dependency on Microsoft.AspNetCore.Mvc.Core 2.2.0. However, the rest of my application was using a lower version.

To fix, check the nuget gallery page for the library, and inspect the Dependencies. Keep lowering the version of the library until it is compatible.

2
votes

To fix that, I updated versions of libraries that where used by both projects (main project and class library) and ensured that versions are exactly the same. After that, the problem seem to disappear.

1
votes

I got the same issue. To fix that, I added this nuget package in my project:

Microsoft.AspNetCore.Mvc.Razor

0
votes

If your application is on .net core 2.0 then that's an issue because Microsoft.AspNetCore.Mvc.Core 2.1.1 is targeted for .net core 2.1. Try removing all references of this nuget and install the nuget targeted for .net core 2.0.

0
votes

My problem was also related to version mismatch. Generally CodeGeneration VS Razor.