Search code examples
c#visual-studiodllreferencefilenotfoundexception

Visual Studio 2022 FileNotFoundException by accessing dll without local copy


I'm using my own DLL in my projects for months without any problems. The DLL is integrated without a local copy, the DLLs are all stored in a directory from where they are integrated. The path is correct and the file definitely exists!

Recently I have had the problem that the compiler reports the following error: FileNotFoundException: The file or assembly "My.Extensions.IO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or a dependency on it was not found. The system cannot find the specified file.

The error only occurs when you want to access the DLL. If you don't use the DLL even though it is integrated, it doesn't complain and the project runs without problems.

However, as soon as I want to access a method or property of the DLL, it reports this error.

I have already seen a few solutions to this or similar problems, but none of them helped me.

  • I have removed the .suo file
  • I deleted the entire .vs
  • I removed the reference entry in the .csproj file
  • I unchecked and rechecked the build checkboxes in the configuration manager for both Debug as and release
  • I tried out building as release

Nothing helps so far...

If I set the reference to local copy = true, it works, but I don't want to do that because I don't want to ship the DLL every time.

I use Visual Studio 2022 Professional

Does anyone have any ideas on what else I can test besides the things I've already tested?

Thanks


Solution

  • By using this command line you can add your DLL to GAC if your DLL is strongly named, so that your project can read the DLL from GAC:

    gacutil -i [YourDLLPath]