Skip to content

Using assembly #9929

Closed
Closed

Description

@jszabo98

"Using assembly" doesn't work in PS 6 as well as in PS 5.1. It's also undocumented in "about_using". https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-6

Steps to reproduce

using assembly system.web

Expected behavior

# successfull execution with no output

Actual behavior

At line:1 char:16
+ using assembly system.web
+                ~~~~~~~~~~
Cannot load assembly 'system.web'.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ErrorLoadingAssembly

Environment data

Name                           Value
----                           -----
PSVersion                      6.1.2
PSEdition                      Core
GitCommitId                    6.1.2
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Jun 18, 2019
  2. bpayette commented on Jun 18, 2019

    @bpayette
    Contributor

    jszabo98 PowerShell Core doesn't support using assembly ... with partial names. If you use the full path to the assembly, it should work.

  3. vexx32 commented on Jun 18, 2019

    @vexx32
    Collaborator

    Seems weird that it doesn't support assembly names. The first thing I think to parallel using assembly is Add-Type -AssemblyName 😕

  4. BrucePay commented on Jun 19, 2019

    @BrucePay
    Collaborator

    Rain Sallow (/u/ta11ow) (@vexx32) In Windows PowerShell, Add-Type has (or had?) a list of partial name to full name mappings so that you could load assemblies by partial name without going through the deprecated-since-forever LoadWithPartialName() API. All of this stuff is related to the GAC but on Core, there is no GAC and no partial names.

  5. SeeminglyScience commented on Jun 19, 2019

    @SeeminglyScience
    Contributor

    Rain Sallow (/u/ta11ow) (@vexx32) In Windows PowerShell, Add-Type has (or had?) a list of partial name to full name mappings so that you could load assemblies by partial name without going through the deprecated-since-forever LoadWithPartialName() API. All of this stuff is related to the GAC but on Core, there is no GAC and no partial names.

    Now it just does Assembly.Load(new AssemblyName(assemblyName)), which will still load from the GAC on Windows, even on Core. I believe non-Windows will still try to load from AppDomain.CurrentDomain.BaseDirectory (which would be where ever pwsh is installed), so System.Web should still work there too.

  6. SeeminglyScience commented on Jun 19, 2019

    @SeeminglyScience
    Contributor

    I think using assembly should have parity with Add-Type -AssemblyName, especially since Windows PowerShell had it.

    Ilya (@iSazonov) Can you remove Resolution-Answered so this isn't closed? I think even if the PowerShell team disagrees, this would need Resolution-Won't Fix instead.

  7. added
    WG-Engine
    Issue-Enhancement
    and removed
    Issue-Question
    Resolution-Answered
    on Jun 20, 2019
  8. iSazonov commented on Jun 20, 2019

    @iSazonov
    Collaborator

    I checked that follow works

     Add-Type -AssemblyName System.Web

    so follow should works too

    using assembly System.Web
    

    even if the PowerShell team disagrees

    Patrick Meinecke (@SeeminglyScience) I am not in MSFT, I am a community maintainer. Sometimes I do a formal moderation based on trusting. "Formal" because I really can not looks every (from 2000!) issue in depth.
    As for "Won't fix" I'd leave this to MSFT experts and PowerShell Committee to mark issues with backward compatibility and security considerations.

  9. SeeminglyScience commented on Jun 20, 2019

    @SeeminglyScience
    Contributor

    I am not in MSFT, I am a community maintainer. Sometimes I do a formal moderation based on trusting. "Formal" because I really can not looks every (from 2000!) issue in depth.
    As for "Won't fix" I'd leave this to MSFT experts and PowerShell Committee to mark issues with backward compatibility and security considerations.

    Oh yeah I know, and you do an awesome job! I'm very glad the repo has you sorting through the chaos 🙂

    I only meant to explain the reasoning behind my request, I 100% understand why you chose the original label.

  10. added
    Resolution-No Activity
    on Nov 16, 2023
  11. mklement0 commented on Dec 26, 2023

    @mklement0
    Contributor

    I just realized I accidentally created a duplicate:

    Indeed, name-only loading of assemblies that PowerShell ships with should work (plus from the GAC, on Windows) - both for symmetry Add-Type -AssemblyName and because using assembly System.Windows.Forms, for instance, works just fine in Windows PowerShell.

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

    Issue-EnhancementResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions