`corehost` not resolving assemblies from immediate app-local directory in portable app
While working on portablizing dotnet, we discovered that corehost does not place app-local assemblies in the TPA list for portable apps. It puts runtime-specific assets (the ones in the runtimes subfolder) on the list, but not ones directly adjacent to the app. This can result in Binding Model issues when the application tries to change the load context because an app-local non-TPA assembly might have loaded and locked the binding model.
/cc @schellap @pakrym
On a related note, corehost should also always ensure the entry-point assembly is on the TPA list. That was the main thing that bit us when we found it. But it was confusing because we though that app-local things always landed on the TPA list.
I thought we are resolving against package relative paths in portable case? Is that only for runtime based assets?
Yeah, that's only for runtime-specific assets. In general, all application modes should put app-local binaries on the TPA list (to prevent locking the binding model). It's just that for runtime-specific assets in portable apps, we need to have a way to structure the binaries so we use relative paths.
FYI, dotnet/cli#2049 did not quite fix this. We need app-local to be used when an assembly is not in the deps file, but if an assembly does appear in the deps file, whatever is resolved for the selected assembly should be used. As an example, if there is the following layout on disk:
MyApp.dll
MyApp.deps.json
MyApp.runtimeconfig.json
System.Net.Http.dll
runtimes/
win/
lib/
netstandard1.5/
System.Net.Http.dll
Then, on any win-derived RID, runtimes/win/lib/netstandard1.5/System.Net.Http.dll should be on the TPA list and System.Net.Http.dll should not be on the TPA list. For all other RIDs, only System.Net.Http.dll should be on the TPA list.
Basically, scooping all the app-local assemblies and putting them on the TPA list should only be done: a) after putting all .deps.json asssemblies on the TPA list and b) ignoring any assembly for which there is already a copy on the TPA list.
The complete resolution order should be something like the following:
- Assemblies in the
depsfile are processed as follows:- If serviced, put the serviced path on the TPA list
- If present in the
DOTNET_PACKAGES_CACHElocation, put that path on the TPA list - Check the app-local version:
- If the target is portable and a RID-specific asset is used: Use the relative path from the
depsfile, concatenated with the app root, and put that on the TPA list. - If the target is portable and a non-RID-specific asset is used: Concatenate the asset file name with the app root and put that on the TPA list.
- If the target is non-portable: Concatenate the asset file name with the app root and put that on the TPA list.
- If the target is portable and a RID-specific asset is used: Use the relative path from the
- Look the package up in package locations (
--additionalprobingpaths,NUGET_PACKAGES, etc.), and if present put that path on the TPA list
- Finally, process assemblies in the app base directory. For each assembly that does not already have a TPA entry with the same assembly name, add that to the TPA list.
/cc @muratg @schellap @pakrym
Tarball of app and fx?
Any portable app referencing net.http with latest cli should show this issue.
I think the code conforms at least mentally, need to debug what is missing...
@pqkrym, this can be closed now?
Yes, this issue seems to be resolved