Skip to content
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

Can't get assembly probing to work; not sure why. #73710

Closed
mavnorthwind opened this issue Aug 10, 2022 · 6 comments
Closed

Can't get assembly probing to work; not sure why. #73710

mavnorthwind opened this issue Aug 10, 2022 · 6 comments

Comments

@mavnorthwind
Copy link

Description

With earlier .NET Framework versions I was used to be able to configure additional paths for assembly probing by adding a
/configuration/runtime/assemblyBinding/probing node to my app.config file.
With .NET 6.0 this doesn't seem to work anymore.
After a lot of searching I found the additionalProbingPaths setting in .runtimeconfig..json, but this didn't work either.

Using the Resolving event from AssemblyLoadContext, I was able to load the assembly from code, but I was hoping for a config way.

Reproduction Steps

Create a library project, add a class, build.
Create an app project (I tried with a WinForms app), add an assembly reference to the library and set "Local copy" to false.
Instantiate a class from the library in the app.
Create a folder "Lib" in your app project, copy the library output to this folder and set "Copy to output" to Always.

Running the app as it is now will throw a FileNotFoundException because .NET doesn't know where to find the library assembly.

Add
"additionalProbingPaths": [
"Lib"
],
to the .runtimesettings.json

Running the app will also throw the FileNotFoundException.

Expected behavior

App will find the assembly in (one of) the paths given in additionalProbingPaths and load it from there.

Actual behavior

Assembly is not being found and a FileNotFoundException is thrown.

Regression?

No response

Known Workarounds

No response

Configuration

{
"runtimeOptions": {
"tfm": "net6.0",
"additionalProbingPaths": [
"Lib"
],
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
]
}
}

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 10, 2022
@huoyaoyuan
Copy link
Member

I remember additionalProbingPaths, but can't find it in official documentation.
See also #72571 (comment).

@ghost
Copy link

ghost commented Aug 11, 2022

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

With earlier .NET Framework versions I was used to be able to configure additional paths for assembly probing by adding a
/configuration/runtime/assemblyBinding/probing node to my app.config file.
With .NET 6.0 this doesn't seem to work anymore.
After a lot of searching I found the additionalProbingPaths setting in .runtimeconfig..json, but this didn't work either.

Using the Resolving event from AssemblyLoadContext, I was able to load the assembly from code, but I was hoping for a config way.

Reproduction Steps

Create a library project, add a class, build.
Create an app project (I tried with a WinForms app), add an assembly reference to the library and set "Local copy" to false.
Instantiate a class from the library in the app.
Create a folder "Lib" in your app project, copy the library output to this folder and set "Copy to output" to Always.

Running the app as it is now will throw a FileNotFoundException because .NET doesn't know where to find the library assembly.

Add
"additionalProbingPaths": [
"Lib"
],
to the .runtimesettings.json

Running the app will also throw the FileNotFoundException.

Expected behavior

App will find the assembly in (one of) the paths given in additionalProbingPaths and load it from there.

Actual behavior

Assembly is not being found and a FileNotFoundException is thrown.

Regression?

No response

Known Workarounds

No response

Configuration

{
"runtimeOptions": {
"tfm": "net6.0",
"additionalProbingPaths": [
"Lib"
],
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
]
}
}

Other information

No response

Author: mavnorthwind
Assignees: -
Labels:

area-Host, untriaged

Milestone: -

@mavnorthwind
Copy link
Author

mavnorthwind commented Aug 11, 2022

@huoyaoyuan This document describes the additionalProbingPaths setting.

@LakshanF
Copy link
Member

The linked issue comment and the document seem to provide context for this issue

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 16, 2022
@vitek-karas
Copy link
Member

.NET 6 intentionally doesn't have a way to add probing - the overall design is for the SDK to construct the entire app.

Note that while additionalProbingPaths can be used to achieve something like this, it's noteasy - the path this property points to is expected to look like NuGet's cache directory - so it needs certain structure for it work, otherwise it will be effectively ignored. It's definitely not just "also look into that directory" and it also only works for assemblies which are actually listed as part of the app in the .deps.json (so SDK knew about them). It will NOT work for Assembly.Load type of usage.

The code approach is the best solution for this - you can write your code to read the location from a config file of some sort.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants