question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to specify a subdirectory for assembly loading

See original GitHub issue

Steps to reproduce

Build a project for .NET Core 3. Add some nuget package. Create a “lib” subdirectory in the output folder. Move some/all of the .dll files into “lib”. Program will fail to run, as it is unable to locate the moved assemblies.

Details

When building a program using the standard framework, which used app.exe.config for its runtime configuration, you could specify private subdirectories that would be searched when resolving assembly loading:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>

I have been unable to find any directives that would reproduce that behavior in the new app.runtimeconfig.json configuration. The runtime spec documentation only mentions searching the root application directory, and doesn’t indicate any means of getting the runtime to search alternate directories (even with the presumed restriction of only being allowed to search private subdirectories).

Use of additionalProbingPaths in app.runtimeconfig.json and app.runtimeconfig.dev.json does not seem to work.

Environment data

dotnet --info output:

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

Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-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: 1.1.14 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 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.202 [C:\Program Files\dotnet\sdk] 2.2.204 [C:\Program Files\dotnet\sdk] 2.2.300 [C:\Program Files\dotnet\sdk] 2.2.400-preview-010219 [C:\Program Files\dotnet\sdk] 3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:40
  • Comments:35 (13 by maintainers)

github_iconTop GitHub Comments

9reactions
0xd4dcommented, Jul 6, 2019

That workaround is ugly and requires too much work.

@Kinematics I’ve successfully removed all files from the root folder and put them in the bin folder. The only thing remaining are the apphost exe files. Nothing else. I already mentioned it above but here’s some more info.

The apphost exe (eg. myapp.exe if your entry point assembly is myapp.dll) has the path to your main dll file. You can patch the apphost exe so instead of having the path myapp.dll in it, it’s bin\myapp.dll. When the exe is started, it will load your file from the bin folder. This is the patcher I use. What’s left is just moving the output to the bin folder and moving the apphost exe to the root and you’re done.

Moving your files to a bin folder is a common request and the SDK should have support for this. All it needs to do is move all files to the bin folder and make sure the apphost exe loads the file from the bin folder.

5reactions
Symbaicommented, Dec 10, 2021

.NET 6 don’t solve this problem, sorry. And I don’t believe .NET 7 will do so, it seems to be very low priority, sadly. Good news is that the unofficial solutions here still work with .NET 6 and some of them are extremely easy to apply. The only official “solution” for this mess is publishing as single-file, well let’s call it workaround to be clear, for the cost of startup performance. If you haven’t already you should upvote the first post. With only 7 upvotes I’m not surprised about its being low priority…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load assemblies with references from subfolders at runtime
I know the subfolder and filename when an Add-On is being loaded, so I simply use Path.GetDirectoryName(System.Reflection.Assembly.
Read more >
Best Practices for Assembly Loading - .NET Framework
Load method and specify complete assembly display names that include different version numbers. For assemblies that are loaded without context, ...
Read more >
Loading .NET Assemblies out of Seperate Folders - Rick Strahl
In this post I describe some of the issues of folder based assembly loading and a brute force solution to deal with assembly...
Read more >
Help with assemblies in NX : r/cad
It seems like an assembly can't reference a part in a nested folder. I.e, if an assembly is in a folder, and it...
Read more >
Windows Explorer crashes when opening folder with a ...
ts file.. Right-click the folder that contains the .ts files then choose properties. In the properties dialog, click the tab 'Customize'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found