Skip to content

Support additional probing paths for assembly loading #3135

Closed

Description

In dotnet core, your dependency dlls do not have to be in the same folder as long as they are installed with nuget at additionalprobingpath.

If you do Add-Type in powershell on linux and then try to use the dll, it will fail with a dependency missing if the dependency is not in the same folder.

Is there a way to let powershell know net core additionalprobingpath? How is this supposed to work properly?

Activity

  1. joeyaiello commented on Feb 13, 2017

    @joeyaiello
    Contributor

    Oh, interesting, so sort of x-copyable GAC...Didn't realize they had done that already.

    If I were to guess, I'd bet that it's probably due to the fact that we currently host an app-local copy of CoreCLR ourselves as opposed to picking up the system-wide "shared framework". Eventually, I think we plan to move to using the system-wide copy, though I'm not sure what the Add-Type behavior should be at that point.

  2. added
    WG-Cmdletsgeneral cmdlet issues
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Feb 13, 2017
  3. added this to the milestone on Mar 7, 2017
  4. joeyaiello commented on Mar 7, 2017

    @joeyaiello
    Contributor

    This absolutely needs to be answered to address the .NET Standard 2.0 "do we, by default, try and load old FullCLR modules?" question.

  5. SteveL-MSFT commented on May 15, 2017

    @SteveL-MSFT
    Member

    even if we don't try by default (perhaps opt-in), we need the ability to load FullCLR assemblies stored in the GAC which seems to be the majority of in-box Windows PowerShell modules

  6. modified the milestones: , , on May 15, 2017
  7. changed the title [-]Question about additional probing path[/-] [+]Support additional probing paths for assembly loading[/+] on May 15, 2017
  8. iSazonov commented on May 16, 2017

    @iSazonov
    Collaborator

    It seems we need to think about the extra configuration option - whether or not to load old FullCLR modules. Perhaps consumers want to block it because of compatibility or performance.

  9. SteveL-MSFT commented on May 16, 2017

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) yes, loading of fullclr modules should be opt-in. perhaps we need some setting in StartupConfig

  10. adityapatwardhan commented on Jun 15, 2017

    @adityapatwardhan
    Member

    Andrew Savinykh (@AndrewSav) Do you have repro steps that I can use to look into this issue?

  11. AndrewSav commented on Jun 15, 2017

    @AndrewSav
    Author

    Aditya Patwardhan (@adityapatwardhan) Here you go.

    Get yourself a clean Ubuntu 16.04 LTS.

    Install Powershell as shown here: https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#ubuntu-1604

    Install .net as shown here https://www.microsoft.com/net/core#linuxubuntu

    Before running step 4 at the link above, change hwapp.csproj and Program.cs as shown here. Then finish step 4.

    Run the following commands:

    cd bin/Debug/netcoreapp1.1
    dotnet hwapp.dll
    

    Observe that "Passed" is printed:

    Passed
    

    Now run the following commands:

    powershell
    Add-Type -AssemblyName ./hwapp.dll
    [hwapp.Program]::GetValue()
    

    Observe an exception:

    Exception calling "GetValue" with "0" argument(s): "Could not load file or assembly 'Microsoft.Extensions.CommandLineUtils, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
    "
    At line:1 char:1
    + [hwapp.Program]::GetValue()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : FileNotFoundException
    
  12. adityapatwardhan commented on Jun 15, 2017

    @adityapatwardhan
    Member

    Andrew Savinykh (@AndrewSav) Thanks! This will be very helpful.

  13. adityapatwardhan commented on Aug 2, 2017

    @adityapatwardhan
    Member

    Andrew Savinykh (@AndrewSav) AdditionalProbingPath is a feature of dotnet / nuget. dotnet run looks up hwapp.runtime.dev.json to find the physical location on the nuget packages folder. When dotnet publish is done the nuget dependency is copied over next to the hwapp.dll. And hence, the add-type scenario works as expected.

    Closing this issue as dotnet publish resolves the issue. Please re-open if you do not agree with the resolution.

  14. undecided2013 commented on May 13, 2019

    @undecided2013

    I am having the same issue on Windows. I wrote a cmdlet targeting .net core 2.1. I 'publish' it. It creates a nuget package. Of course I cannot load that into powershell. So I go to the bin\Release\netcoreapp2.1 folder. I Add-Type the dll that contains the cmdlet. That works fine. I can now execute my cmdlet with -? and I get the help. Trying to execute it though and I get Could not load file or assembly '.......'. The system cannot find the file specified. This is an OSS assembly I got from nuget. This same code works fine as a console app but fails in powershell. So, the rules for finding referenced assemblies is not the same.

  15. vexx32 commented on May 13, 2019

    @vexx32
    Collaborator

    Yep, there was a change in PS 6.2 which makes this a whole lot harder; see here: #9488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-By DesignThe reported behavior is by design.WG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions