Powershell: Using assembly

Created on 18 Jun 2019  路  7Comments  路  Source: PowerShell/PowerShell

"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
Issue-Enhancement WG-Engine

Most helpful comment

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

@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.

All 7 comments

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

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

@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.

@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.

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

@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.

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

@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.

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.

Was this page helpful?
0 / 5 - 0 ratings