5

I have two class library projects and one Web API project. Let it be ClassLibrary1, ClassLibrary2, WebApi.
I add link for Web API to both ClassLibrary1 and ClassLibrary2 as a project reference.
In addition, ClassLibrary1 has link to ClassLibrary2 as a project reference.

At the compilation stage, I have no errors, But in runtime, I got the next error:
Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

All Nuget packages have the same versions for these projects.

enter image description here

Hanna Holasava
  • 192
  • 1
  • 15
  • try to check your "CopyLocal" flag and rebuild the project. – Timur Sidoryuk Aug 25 '20 at 07:31
  • Which is your start project? You cannot run libs, so there should be a driver. Have a look into that project's bin folder. Are all expected dlls present? – Fildor Aug 25 '20 at 07:32
  • 3
    @Fildor Yep, ClassLibrary1.dll and ClassLibrary2.dll exists in the bin folder. – Hanna Holasava Aug 25 '20 at 07:37
  • @TimurSidoryuk Where can I find 'CopyLocal' flag? – Hanna Holasava Aug 25 '20 at 07:46
  • @HannaHolasava you can find it here: https://pasteboard.co/JnYjeNh.png – Timur Sidoryuk Aug 25 '20 at 08:13
  • @TimurSidoryuk links to the class libraries are added as project references. It's under Dependencies/Projects, not under Dependencies/References. I set 'Copy Local' and 'Copy Local Satellite Assemblies' to YES, for links in Web API project, it doesn't help – Hanna Holasava Aug 25 '20 at 08:23
  • @HannaHolasava I now check it on my machine. Create .net core 3.1 web api and two class libraries. And it runs good. Also i found, that you don't need to reference at classLibrary2 in your case, because it already included in classLibrary1 reference Can you provide minimal reproducible example of your problem? Maybe 3 pieces of your projects? – Timur Sidoryuk Aug 25 '20 at 09:47
  • 1
    @TimurSidoryuk thanks you very much for the help. The problem was resolved when I removed the solution from my local storage and reloaded it from the repository. Maybe It was some old settings for the Visual Studio. – Hanna Holasava Aug 26 '20 at 11:06

2 Answers2

2

You can refer to the following steps to check the project.

  1. Please ensure the target framework of the project and the development platform are the same.

  2. Please ensure the reference project comes from:\ClassLibraryx\bin\Debug\ClassLibraryx.dll

  3. If there are no problems with the above two, you could try the following steps:

    (1)Remove project references

    (2)Rename two class library projects and rebuild

    (3)Re-add project references

dear_vv
  • 2,350
  • 1
  • 4
  • 13
1

The problem was resolved when I removed the solution from my local storage and reloaded it from the repository.

Hanna Holasava
  • 192
  • 1
  • 15
  • That's great! You can click '✔' to mark your reply as an answer. This will help others facing the same problem. – dear_vv Aug 28 '20 at 01:55