The software that I am developing uses a system of loadable plugins discovered at run-time and loaded through Reflection. Each of the plugins has its own set of DLLs that mostly originate from various Nuget packages. When I publish a self-contained deployment for a particular platform, some of the plugins load successfully but others throw exceptions similar to below:
Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
or
Could not load file or assembly 'MailKit, Version=2.10.0.0, Culture=neutral, PublicKeyToken=4e064fe7c44a8f1b'. The system cannot find the file specified.
etc. The DLLs with the names mentioned above (ex: System.Data.SqlClient.dll, MailKit.dll) do exist in the publish
subfolder of the solution, yet they are still reported as missing by the Activator.CreateInstance()
call, whereas the rest of a few dozen DLLs load fine. As long as I do not publish, the project runs fine and unit tests are able to pass through the code that uses these DLLs. When I check properties of the faulty packages, they seem to be different versions from what is reported above. Example, for Nuget package System.Data.SqlClient 4.8.2
I see:
This does not match 4.6.1.2 reported by the exception.
What is causing this mess, and what has to be done in VS, .csproj, or dotnet publish
command, to have ALL DLLs consistently and correctly published?
Any mention of different versions of Visual Studio or .NET Core is offtopic. I am locked in these and have to work with what I am told to.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…