Skip to content

'Add-Type' produces different assemblies when running the same source code multiple times in PS Core #5515

@daxian-dbw

Description

@daxian-dbw

On Windows PowerShell, Add-Type returns the same assembly when running it multiple times with the same source code.
While on PowerShell Core, Add-Type returns different assemblies when running it multiple times with the same source code.

Steps to reproduce

> $code = @'
public class Foo {
    public string Name = "name";
}
'@
> (Add-Type $code -PassThru).Assembly.FullName

Expected behavior

Like on Windows PowerShell, the same assembly is returned when using the same source code.

> (Add-Type $code -PassThru).Assembly.FullName
4woxc1pb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
> (Add-Type $code -PassThru).Assembly.FullName
4woxc1pb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
> (Add-Type $code -PassThru).Assembly.FullName
4woxc1pb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

Actual behavior

> (Add-Type $code -PassThru).Assembly.FullName
z4vydr0b.yke, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
> (Add-Type $code -PassThru).Assembly.FullName
gyos43ig.yjb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
> (Add-Type $code -PassThru).Assembly.FullName
wsxcciz3.544, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-rc
PSEdition                      Core
GitCommitId                    v6.0.0-rc-3-g5702081ae6d116455f6cff30e7b509abf21ae609
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions