asp.netasp.net-core.net-corefilenotfoundexception.net-standard

FileNotFOundException on runtime


I have an old asp.net website that references a .net Framework 4.8.1 Class Library.

I wanted to use this class library in other class libraries that are going to be .net 8.0. I decided to retarget this class library to .net standard 2.0. I had quite a bit of work recording stuff and moving some out of it to a different library but after a bit of work everything compiled again.

However when i now try to run that asp.net website i get a runtime error of:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

The asp.net website did indeed still have a reference to this version. I have however deleted this and added a reference through nuget for the 5.0.0 version (same as I have in the net standard class library). But this error keeps popping up. The module reporting the error is the net standard class library. I have no other references anywhere to that version of annotation, all other libraries also use 5.0.0.

Any suggestions?


Solution

  • I changed the project to multi target frameworks and this fixed the runtime error(s).