Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add-Type should not fail when default referenced assemblies are specified with -ReferencedAssemblies #3779

Copy link
Copy link
@bmanikm

Description

@bmanikm
Issue body actions

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 $requiredAssembly

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility moduleWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.