-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assembly.Load(string assemblyName) throws a FileNotFoundException #13511
Comments
I also tried to add the additional dependency to the
Still, the assembly does not get loaded and the FileNotFoundException is thrown. This is my modified
|
Assembly.Load in .NET Core works by default only for assemblies that have been published as part of the app. Is there a reason why you are coping Newtonsoft.Json.dll to your app manually instead of just referencing Newtonsoft.Json NuGet package? There are two primary ways to solve the problem:
|
@jkotas The reason we came across this problem is that one of our public libraries (deployed as a nupkg) depends on an another internal nuget package that
That's why we set set its assemblies as private assets in the csproj of the public library:
And instead just copy the assemblies to the output directory in a nuget build target:
In the old days this would have worked because as soon an API in the public library is used, the CLR would have loaded the dependent assemblies automatically from the probing path.
Based on what I just described, it seems that this is our only option. I have two questions:
|
You may consider referencing the InternalPackage with
It will automatically load the dependent assemblies only if they are part of the app. |
What does "part of the app" actually mean? That they are located in the probing path? That they exist in |
It means that the build system knows about it. If the build system knows about the .dll:
|
cc @vitek-karas |
Well first of all, we don't build apps, our customers do. We only build nupkgs that our customers can use. |
Assuming that the correct version of
NewtonSoft.Json.dll
was located in the same folder as the executing exe (i.e. in the probing path), this code used to work in classic .NET (4.7.2):But in .NET Core, we will get the following exception:
This leaves anyone who is porting a .NET classic application or library to .NET Core with the following questions:
runtimeconfig.json
and (or?)runtimeconfig.dev.json
like sobut that didn't change anything.
COREHOST_TRACE=1
andCOREHOST_TRACEFILE=<path>
. But the output that is generated by it absolutely does not help to figure out why the assembly was not found. It doesn't show the binding error itself and also doesn't show where it tried to find that assembly.The text was updated successfully, but these errors were encountered: