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

AssemblyLoadContext: Loading of assemblies from 'runtimes' folder #13015

Open
shvez opened this issue Jul 1, 2019 · 5 comments
Open

AssemblyLoadContext: Loading of assemblies from 'runtimes' folder #13015

shvez opened this issue Jul 1, 2019 · 5 comments

Comments

@shvez
Copy link

shvez commented Jul 1, 2019

@vitek-karas you asked me here(https://github.com/dotnet/coreclr/issues/13277) to create a new issue. here it is.

In short:
My plugin application has a dependency from System.Diagnostics.PerformanceCounter.dll. I publish it as dotnet publish -f netcoreapp3.0

The issue is that if I just build my loader and start it, it loads plugin application without any issues. It takes a version of the library from runtimes folder.
if I publish Loader application like 'dotnet publish -f netcoreapp3.0 -r win-x64' (it is important that I use RID 'win-x64', not 'win10-x64') it loads System.Diagnostics.PerformanceCounter.dll assembly from the plugin application folder. And this version is generating an exception that platform is not supported.

I've checked the trace file for failure case and found out that it can not load from runtimes folder because RID win10-x64 is not compatible with platform 'win' where System.Diagnostics.PerformanceCounter.dll is situated. runtimes\win\lib\netcoreapp2.0\System.Diagnostics.PerformanceCounter.dll to be precise. I do not see such message for NotPublished version
EDIT:
trace snippet for published version

Adding runtimeTargets runtime asset runtimes/win/lib/netcoreapp2.0/System.Diagnostics.PerformanceCounter.dll rid=win assemblyVersion=4.0.1.0 fileVersion=4.700.19.30308 from System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8
The targeted framework does not support the runtime 'win10-x64'. Some native libraries from [System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8] may fail to load on this platform.
Adding runtime asset lib/netstandard2.0/System.Diagnostics.PerformanceCounter.dll assemblyVersion=4.0.1.0 fileVersion=4.700.19.30308 from System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8
Reconciling library System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8

trace snippet for non published version

Adding runtimeTargets runtime asset runtimes/win/lib/netcoreapp2.0/System.Diagnostics.PerformanceCounter.dll rid=win assemblyVersion=4.0.1.0 fileVersion=4.700.19.30308 from System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8
Adding runtime asset lib/netstandard2.0/System.Diagnostics.PerformanceCounter.dll assemblyVersion=4.0.1.0 fileVersion=4.700.19.30308 from System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8
Reconciling library System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8

difference is this line:

The targeted framework does not support the runtime 'win10-x64'. Some native libraries from [System.Diagnostics.PerformanceCounter/4.6.0-preview6.19303.8] may fail to load on this platform.

End of EDIT

What do I do wrong? What should I do to get it working correctly? I need a version of my application which may run on windows, on linux, and on mac.

here is netcore info:

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview6-012264
 Commit:    be3f0c1a03

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\

Host (useful for support):
  Version: 3.0.0-preview6-27804-01
  Commit:  fdf81c6faf

.NET Core SDKs installed:
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

here are links to trace files and to sample application:
Loader app sample: https://www.dropbox.com/s/lqragpd26vfccr2/Loader.7z?dl=0
it contains Loader - app, Application - the plugin, AppInterfaces - common interface lib.
'_out' folder which contains 'dev' folder with build results and 'publish' folder with results of publishing.

trace_p.7z(https://www.dropbox.com/s/vfwbzgfoyqf4umb/trace_p.log.7z?dl=0) - zipped version of trace for the version from 'publish' folder
trace.7z(https://www.dropbox.com/s/613qu1n8wy5a3rv/trace.log.7z?dl=0) - zipped version of trace for the version from 'dev' folder

to start dev version you may use visual studio. to start published version you have to go to '_out/publish/Loader' folder and start Loader.exe

@shvez
Copy link
Author

shvez commented Jul 3, 2019

From the traces I've attached to the initial post, I found out that in case of the published version the rid fallback graph is empty. I think this could be a reason for The targeted framework does not support the runtime 'win10-x64' message

@vitek-karas
Copy link
Member

This is a known problem with the component loading in self-contained apps. The master issue is here: https://github.com/dotnet/core-setup/issues/6961. In your case you're specifically hitting https://github.com/dotnet/core-setup/issues/6960.

Unfortunately I'm currently not aware of a good workaround. The only one I can think of is to add some code into your AssemblyLoadContext.Load and handle this case specifically. Alternatively you could modify the build of your host app and manually add the RID fallback graph into its .deps.json - then it should work. If you only have one or two cases like this I would probably go with the custom code in the load context - it's not clean, the host app has to know about which libraries the plugin loads - but it's probably the least amount of trouble.

@shvez
Copy link
Author

shvez commented Jul 9, 2019

thank you for response

are you going to fix those issues before netcore 3 release?

@vitek-karas
Copy link
Member

I don't think it will happen - the one you're hitting we might be able to as it's just an SDK change, doesn't require fixes in the host or the runtime. The other will very likely not happen as it requires changes both in SDK and the host.

@shvez
Copy link
Author

shvez commented Jul 9, 2019

well, one more possible solution is the publishing of plugin with an explicit platform. Some what like -r win-x64.
Although it may work for us (with a tradeoff of creating multiple copies of the same code in binary form) it may in some cases create troubles for our customers, who also provides plugins for our plugins

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@agocke agocke modified the milestones: 5.0.0, 6.0.0 Aug 4, 2020
@vitek-karas vitek-karas modified the milestones: 6.0.0, Future Aug 10, 2021
@agocke agocke added this to AppModel Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants