You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'#Requires -Assembly' does not have any effect #11098
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.
Nothing get's loaded and it throws no error. No matter if it's valid input or not.
With Add-Type -Assembly 'Name.For.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123' could be loaded.
Requires for Administrator and Modules work like expected.
Name Value
---------
PSVersion 7.0.0-preview.5
PSEdition Core
GitCommitId 7.0.0-preview.5
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---------
PSVersion 5.1.14393.206
PSEdition Desktop
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
BuildVersion 10.0.14393.206
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Ilya (@iSazonov) It is unclear from these issues whether or not #Requires -Assembly should be supported. Documentation suggests there is support, but this issue states the statement has no effect.
If #Requires -Assembly is not supported, than we should throw an error instead of failing silently.
I suspect it remains for compatibility with PS 5.1 -- my guess is that's been discussed elsewhere, but can't remember.
Basically:
using assembly is preferred to #require -Assembly because it should try to load something rather than just fail if it's not loaded already. #require has a tradition of being an assertion rather than performing an action, and also presents as a comment pragma and isn't stored in an AST, meaning it's not as good a fit.
But because acceptance for the syntax (even if it does nothing) was added in PS 5.1, removing it would cause parse errors for scripts that would otherwise "just work" in migration from 5.1 to 7. So given the choice between a wart and a hard failure, the wart was chosen.
I think the question remains open for whether it should be removed for PS vNext
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.
Activity
iSazonov commentedon Nov 18, 2019
Mettcon (@Mettcon) Please look #5022 and referenced there RFC.
vexx32 commentedon Nov 18, 2019
Ilya (@iSazonov) does the
using assemblyalternative permit a fully qualified assembly name?iSazonov commentedon Nov 18, 2019
Yes, #5022 and PowerShell/PowerShell-RFC#122 reject
#Requires -AssemblyTracking issues #9929 #6653
xtqqczze commentedon May 5, 2020
Ilya (@iSazonov) It is unclear from these issues whether or not
#Requires -Assemblyshould be supported. Documentation suggests there is support, but this issue states the statement has no effect.If
#Requires -Assemblyis not supported, than we should throw an error instead of failing silently.iSazonov commentedon May 5, 2020
xtqqczze What is a behavior on Windows PowerShell 5?
xtqqczze commentedon May 6, 2020
Ilya (@iSazonov) According to MicrosoftDocs/PowerShell-Docs#4518, the
#Requires -Assemblyfeature was present in Windows PowerShell 5.1 (and likely earlier).However, my tests in Windows PowerShell 5.1 show the behaviour is the same, i.e. nothing is loaded and no error is thrown.
iSazonov commentedon May 6, 2020
Perhaps Rob Holt (@rjmholt) could comment - should we remove the parameter?
rjmholt commentedon May 6, 2020
I suspect it remains for compatibility with PS 5.1 -- my guess is that's been discussed elsewhere, but can't remember.
Basically:
using assemblyis preferred to#require -Assemblybecause it should try to load something rather than just fail if it's not loaded already.#requirehas a tradition of being an assertion rather than performing an action, and also presents as a comment pragma and isn't stored in an AST, meaning it's not as good a fit.I think the question remains open for whether it should be removed for PS vNext
iSazonov commentedon May 6, 2020
It is your RFC :-)
I think we should update docs with "that currently it is not work on 5 and 7 versions and will be probably removed in future."