sdk icon indicating copy to clipboard operation
sdk copied to clipboard

`corehost` not resolving assemblies from immediate app-local directory in portable app

Open analogrelay opened this issue 10 years ago • 9 comments

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

analogrelay avatar Mar 24 '16 23:03 analogrelay

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.

analogrelay avatar Mar 24 '16 23:03 analogrelay

I thought we are resolving against package relative paths in portable case? Is that only for runtime based assets?

schellap avatar Mar 25 '16 01:03 schellap

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.

analogrelay avatar Mar 25 '16 03:03 analogrelay

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:

  1. Assemblies in the deps file are processed as follows:
    1. If serviced, put the serviced path on the TPA list
    2. If present in the DOTNET_PACKAGES_CACHE location, put that path on the TPA list
    3. Check the app-local version:
      1. If the target is portable and a RID-specific asset is used: Use the relative path from the deps file, concatenated with the app root, and put that on the TPA list.
      2. 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.
      3. If the target is non-portable: Concatenate the asset file name with the app root and put that on the TPA list.
    4. Look the package up in package locations (--additionalprobingpaths, NUGET_PACKAGES, etc.), and if present put that path on the TPA list
  2. 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

analogrelay avatar Mar 25 '16 16:03 analogrelay

Tarball of app and fx?

schellap avatar Mar 25 '16 17:03 schellap

Any portable app referencing net.http with latest cli should show this issue.

pakrym avatar Mar 25 '16 17:03 pakrym

I think the code conforms at least mentally, need to debug what is missing...

schellap avatar Mar 25 '16 17:03 schellap

@pqkrym, this can be closed now?

schellap avatar Mar 28 '16 16:03 schellap

Yes, this issue seems to be resolved

pakrym avatar Mar 28 '16 16:03 pakrym