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
Suggestion: Add #Requires -Assembly AssemblyName support #5022
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.
PetSerAl I wasn't aware of the using keyword, though I don't see assembly documented as an argument to it. Also, our servers are not uniformly on PowerShell 5 just yet, so that extended syntax isn't something we can fully rely on yet (my workstation is stuck on version 5.0.10105.0-April2015Preview which doesn't support using assembly, and I'm unable to upgrade or downgrade or uninstall it from Windows 7). It seems odd to have another thing that must come first in the script, along with [CmdletBinding()]Param(…). It looks like usingmust precede [CmdletBinding()]Param(…).
The reason I use the above formulation is to Add-Type only if referencing the type causes an exception, that way I'm only adding it once per session.
I'll have to look into the using syntax (I hope it gets added to the docs, and is officially supported) once I can finally upgrade things and get the new features.
However, even on a newer machine, there's a pretty big performance difference:
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.
Activity
PetSerAl commentedon Oct 5, 2017
Why do you put
Add-Typeincatch? You could also putusing assembly System.Configurationon top of script.JasonG-STCU commentedon Oct 5, 2017
I, too, have used this in a script of mine. It would absolutely be beneficial to be able to include it this way.
brianary commentedon Oct 5, 2017
PetSerAl I wasn't aware of the
usingkeyword, though I don't seeassemblydocumented as an argument to it. Also, our servers are not uniformly on PowerShell 5 just yet, so that extended syntax isn't something we can fully rely on yet (my workstation is stuck on version 5.0.10105.0-April2015Preview which doesn't supportusing assembly, and I'm unable to upgrade or downgrade or uninstall it from Windows 7). It seems odd to have another thing that must come first in the script, along with[CmdletBinding()]Param(…). It looks likeusingmust precede[CmdletBinding()]Param(…).The reason I use the above formulation is to
Add-Typeonly if referencing the type causes an exception, that way I'm only adding it once per session.PetSerAl commentedon Oct 6, 2017
You can not load same assembly twice anyway. No harm on calling
Add-Typefor already loaded assembly.brianary commentedon Oct 6, 2017
I'll have to look into the
usingsyntax (I hope it gets added to the docs, and is officially supported) once I can finally upgrade things and get the new features.However, even on a newer machine, there's a pretty big performance difference:
on my older machine, it's even bigger:
rjmholt commentedon Mar 23, 2018
I've opened an RFC on updating the behaviour of
#requires. Please feel free to comment in the PR.