-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
This regression got introduced with #3556. This impacted the functionality of PowerShellGet module in PowerShellCore beta1 release (https://github.com/PowerShell/PowerShellGet/issues/125).
I think, Add-Type should ignore -ReferencedAssemblies if that is not applicable on PowerShellCore.
Add-Type should still support -ReferencedAssemblies for assemblies which are not referenced by default in PowerShellCore.
This impacts all PowerShell Script modules which uses Add-Type with -ReferencedAssemblies. Please ensure that this is not another SemanticVersion related issue in PowerShellCore for 2 part version comparison with $PSVersionTable.PSVersion .
Repro
$requiredAssembly = @([System.Management.Automation.PSCmdlet].Assembly.FullName)
$source = @"
using System.Management.Automation;
namespace Microsoft.PowerShell.Commands.PowerShellGet
{
[Cmdlet("Get", "Test")]
public class Telemetry : PSCmdlet
{
protected override void ProcessRecord()
{
WriteObject(new { ArtifactsNotFound = "abc" });
}
}
}
"@
Add-Type -TypeDefinition $source -Language CSharp -Verbose -PassThru -ReferencedAssemblies $requiredAssemblyExpected Behavior
Add-Type runs successfully, link on Windows PowerShell v 5.1
Actual Behavior
Add-Type : (1) : Missing compiler required member 'System.Collections.Generic.EqualityComparer`1.Equals'
(1) : >>> using System.Management.Automation;
(2) : namespace Microsoft.PowerShell.Commands.PowerShellGet
At line:1 char:1
+ Add-Type -TypeDefinition $source -Language CSharp -Verbose -PassThru ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : (1) : Missing compiler required member 'System.Collections.Generic.EqualityComparer`1.GetHashCode'
(1) : >>> using System.Management.Automation;
(2) : namespace Microsoft.PowerShell.Commands.PowerShellGet
At line:1 char:1
+ Add-Type -TypeDefinition $source -Language CSharp -Verbose -PassThru ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : (1) : Missing compiler required member 'System.Collections.Generic.EqualityComparer`1.get_Default'
(1) : >>> using System.Management.Automation;
(2) : namespace Microsoft.PowerShell.Commands.PowerShellGet
At line:1 char:1
+ Add-Type -TypeDefinition $source -Language CSharp -Verbose -PassThru ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. Compilation errors occurred.
At line:1 char:1
+ Add-Type -TypeDefinition $source -Language CSharp -Verbose -PassThru ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
Environment
Name Value
---- -----
PSVersion 6.0.0-rc
PSEdition Core
GitCommitId v6.0.0-rc
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
Solution/Workaround
Add-Type now implicitly include all netcoreapp2.0 reference assemblies and System.Management.Automation by default with -ReferenceAssembly is not specified. So running Add-Type without -ReferenceAssembly will work.