Search code examples
asp.net-coreversionnuget-package-restoresystem.web.net-4.6.1

System.Web.ApplicationServices in .NET Core 2


I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution

package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.

The app is also throwing this exception below when I call code in one of the custom packages

System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified

Is there any way around this other than re-writing the code in my web Api?


Solution

  • No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.

    Long and short, if there's any dependency on System.Web at all, you can't use it.