Skip to content

System.Runtime.Loader not copied to output directoryΒ #22732

Closed

Description

@bencyoung

Hi,

I'm using 2.0.0-preview1-25305-02 and I have an issue with mixed netstandard and net462 projects in the same solution. Not sure if I'm doing something wrong or if there's something else.

I have a net462 app that loads another net462 dll containing some Unity hosting code. That in turn loads some other dlls, some of which are netstandard2.

On app startup I'm getting:

---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I had thought this was part of netstandard, but either way I've added it as a NuGet package dependency to the Unity project (seeing as that's the one that does dynamic loading), but for some reason it's not ending up in either the Unity project bin folder or the exe one. Do you know why this dll is not being deployed to the bin folder?

Thanks,
Ben Young

Activity

  1. bencyoung commented on Jul 12, 2017

    @bencyoung
    Author

    The Fusion log looks like

    === Pre-bind state information ===
    LOG: DisplayName = System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
     (Fully-specified)
    LOG: Appbase = file:///F:/Dev/.../src/Examples/ExampleHost/bin/Debug/net462/
    LOG: Initial PrivatePath = NULL
    Calling assembly : FIS.Risk.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: F:\Dev\...\src\Examples\ExampleHost\bin\Debug\net462\FIS.Risk.Core.ExampleHost.exe.Config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    LOG: Attempting download of new URL file:///F:/Dev/.../src/Examples/ExampleHost/bin/Debug/net462/System.Runtime.Loader.DLL.
    LOG: Attempting download of new URL file:///F:/Dev/.../src/Examples/ExampleHost/bin/Debug/net462/System.Runtime.Loader/System.Runtime.Loader.DLL.
    LOG: Attempting download of new URL file:///F:/Dev/.../src/Examples/ExampleHost/bin/Debug/net462/System.Runtime.Loader.EXE.
    LOG: Attempting download of new URL file:///F:/Dev/.../src/Examples/ExampleHost/bin/Debug/net462/System.Runtime.Loader/System.Runtime.Loader.EXE.
    
  2. jnm2 commented on Jul 12, 2017

    @jnm2
    Contributor

    I'm interested, running into a similar issue with NUnit.Xamarin too on monoandroid71.

  3. bencyoung commented on Jul 12, 2017

    @bencyoung
    Author

    If I drop in a dll from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.loader\4.3.0\lib\netstandard1.5 then I get:

    Resolving FIS.Risk.Core.Logging.NullLogger,(none) (mapped from FIS.Risk.Core.Logging.ILogging, (none))
    ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

  4. bencyoung commented on Jul 12, 2017

    @bencyoung
    Author

    If I drop in from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.loader\4.0.0\lib\netstandard1.5 then I get:

    Resolving FIS.Risk.Core.Logging.NullLogger,(none) (mapped from FIS.Risk.Core.Logging.ILogging, (none))
    ---> System.TypeLoadException: Could not load type 'System.Runtime.Loader.AssemblyLoadContext' from assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

  5. joperezr commented on Sep 25, 2017

    @joperezr
    Member

    hey @bencyoung , have you tried this again with netcoreapp/netstandard 2.0? I ask because we added some tooling fixes that would add a reference to a compatibility package that will make referencing net461 dependencies work, so I wonder of that fixes your problem. Let me know if you still see the issue.

  6. bencyoung commented on Sep 26, 2017

    @bencyoung
    Author

    I'm still getting the issue unfortunately.

    A problem occurred when trying to run the application.: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
    File name: 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral,...'
       at FIS.Risk.Core.Hosting.ComponentRunner.RunnerState..ctor(IReadOnlyList`1 args, IComponent component, Action hostingStop, Action hostingRestart, TimeSpan joinWait)
       at FIS.Risk.Core.Hosting.ComponentRunner.RunAsConsole(IReadOnlyList`1 args)
    
  7. bencyoung commented on Sep 26, 2017

    @bencyoung
    Author

    The version of System.Runtime.Loader that's ending up in the bin folder is:

    image

  8. bencyoung commented on Sep 26, 2017

    @bencyoung
    Author

    Here's a minimal reproduction

    BugDemo.zip

  9. DVoavi-Arison commented on Oct 2, 2017

    @DVoavi-Arison

    Running into the same issue with loader 4.3.0 even if I do copy the dll itself to the output folder before running.

  10. aienabled commented on Oct 25, 2017

    @aienabled

    Same issue with System.Runtime.Loader 4.3.0 and net471.
    UPD. Found this https://github.com/dotnet/cli/issues/6019

  11. sereeth commented on Dec 20, 2017

    @sereeth

    Having the exact same issue, something is definitely wrong here. Side by side .netcore 2/4.7.1/.NET Standard 2 and System.Runtime.Loader is never copied. Blows up standard dependency injection code using AssemblyLoadContext

  12. jugg1es commented on Feb 12, 2018

    @jugg1es

    any resolution to this?

  13. bobuva commented on Jul 20, 2018

    @bobuva

    Asking if there's any resolution to this.

  14. nikunjratanpara commented on Jul 29, 2018

    @nikunjratanpara

    I am facing the same issue with .Net framework 4.6.1 with some reference to .Net Standard 2.0 libraries.
    Please share workaround or resolution to this.

  15. alexdegroot commented on Jul 29, 2018

    @alexdegroot

    @nikunjratanpara When using the full framework, I went back to the traditional 'Assembly.Load' methods. Very unfortunate, but not way around this as we speak.

  16. 12 remaining items

  17. jons-aura commented on Feb 15, 2019

    @jons-aura

    I'm having the same issue as @phatcher with .Net 4.6.1 as the target while running unit tests. Is it not possible to use a .Net Standard 2.0 library in a .Net Framework project? That would seem to negate the entire purpose of having .Net Standard at all.

  18. watsonsong commented on Mar 15, 2019

    @watsonsong

    I met the same problem when I use .netcore 3.0 preview, is there any one met the same problem?

  19. ericstj commented on Mar 15, 2019

    @ericstj
    Member

    @phatcher / @jons-aura / @watsonsong can you all clarify what it is you're asking?

    System.Runtime.Loader is not supported on desktop: full stop. You cannot use it there, we have no implementation of this API on .NETFramework. It's current failure mode (FileNotFoundException) is by design, we can talk about changing that (eg: PlatformSupportedException) but I suspect that's not really going to help enable whatever that's attempting to use this API.

    If the ask is to support this API on desktop folks should start describing the scenarios they want to work and folks like @jeffschwMSFT and @jkotas can have a look provide a recommendation.

  20. jons-aura commented on Mar 15, 2019

    @jons-aura

    What I'm asking for is the ability to use a .Net Standard library built with .Net Core in a .Net 4.6 Framework project. When I run unit tests in Azure with this scenario the tests crash.

  21. ericstj commented on Mar 15, 2019

    @ericstj
    Member

    @jons-aura can you open a new issue describing that? It sounds different than what this issue is tracking (System.Runtime.Loader, specifically). I suspect you are hitting a case of missing the support libraries from your .NET Framework 4.6.1 project, but it'd be best to open a new issue that describes the issue and along with a repro if you can. Important things to note are the projects involved, their target frameworks, how they reference each other, and whether they are using nuget-packages.config vs nuget-packagereference. Tag me @ericstj on the new issue and I'll have a look. Thanks!

  22. phatcher commented on Apr 13, 2019

    @phatcher

    @ericstj My problem I think is that netframework/netcore binaries are getting mixed up during the compilation phase on Azure DevOps causing the "Could not load error..." since it's only supported on netcore

    All of my projects are using packagereference and the source nuget packages are targeting both netstandard and netframework and I have the settings as below

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    

    I've also checked and the vstest.console is only picking up net472 test assemblies though the test adapter path is as per @jons-aura case to "D:\a\1\s"

    It's difficult getting to a simple repo as it's a 60 project solution that's failing, whereas the 85 project solution with the library code compiles and tests correctly on DevOps; which is why I think it's some form of errant reference but I've been through the project files a number of times trying to find it.

  23. apobekiaris commented on Aug 27, 2019

    @apobekiaris

    worked for me after upgrading to 4.8

  24. CleverAtBen commented on Nov 5, 2019

    @CleverAtBen

    @phatcher Did you solve your problem?? I am experiencing exactly the same experience on Azure DevOps

  25. transferred this issue fromdotnet/corefxon Jan 31, 2020
  26. added this to the Future milestone on Jan 31, 2020
  27. joperezr commented on Jul 1, 2020

    @joperezr
    Member

    It is not clear here what (if anything) should be fixed in the runtime repo as most people hitting this problem are usually due to a misconfiguration on their project causing .NET Core libraries to end up on their .NET Framework applications. For this reason I'll go ahead and close this issue for now but feel free to reopen if you think otherwise.

  28. ghost locked as resolved and limited conversation to collaborators on Dec 21, 2020
  29. removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.RuntimequestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions