Search code examples
c#.netweb-applicationsvisual-studio-2019

Visual Studio 2019 Error - Could not load file or assembly or one of its dependencies


I have some trouble with running my project. When I try to run, the following error appears:

FileNotFoundException: Could not load file or assembly 'Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified

Context:

I have a Class Library X and a Web Application Y which have dependencies on X. When I try to run my API project, it throws the above error. BUT, when my colleagues try to run the same API project, it works fine (no errors, and in /bin folder, it loads all the .dll libraries..)

I did those approaches:

  • Restart Visual Studio, clean and build a solution
  • Remove the class library references and add it again
  • Tools > Import and Export Settings Wizard > Reset all settings (maybe some setting was not well configured). I also tried to import colleague settings and didn't work either.

I tried various approaches(even in a different machine, but same VS settings) but none of these worked for me.

Visual studio 2019 16.4 Enterprise.


Solution

  • thank you for your solutions but I found the problem:

    The project solution has some projects with .net standard 2.0 and some with .net framework 4.8. Somehow, when I run the app, some packages are not loaded correctly and it throws an error.

    That line below solved my problem:

    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    

    Put it in all .net framework 4.8 projects on first XML tag.

    Thank your for all.

    Regards.