-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
This is a regression from Windows PowerShell, where the - useful - behavior is as follows:
-
If you repeatedly call
Add-Type -TypeDefinition/-MemberDefinitionfor the same target type, only the first invocation adds the type to the session and subsequent calls are benign - and fast - no-ops, if the source code is unchanged. -
If you modify the source code, you get an error along the lines of:
Add-Type : Cannot add type. The type name '<name>' already exists.
This behavior is sensible, as it alerts you to the fact that trying to change the type in-session isn't possible.
By contrast, PowerShell Core now quietly ignores attempts to change the type, which means that you may not notice that your changes didn't take effect.
Steps to reproduce
Run the following Pester test
{
Add-Type -TypeDefinition @'
public class Foo {}
'@
# Try to redefine the type with different source code.
Add-Type -TypeDefinition @'
public class Foo { public int Bar {get {return 42;} } }
'@
} | Should -ThrowExpected behavior
The test should succeed, because an error should be emitted.
Actual behavior
The test fails, because no error is emitted, because the second Add-Type is effectively quietly ignored [a new assembly is actually being created - see
@daxian-dbw's comment below]
Environment data
PowerShell Core v6.2.0