Skip to content

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

Closed

Description

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

Activity

  1. iSazonov commented on Nov 21, 2017

    @iSazonov
    Collaborator

    Currently Add-Type get a source code as string (even files are merged into a single string), evaluate a hash and save the hash in a cache. It allow avoid recompile the source code and reload it in new assembly. So we could fix the Issue and returm previous assembly from the cache as I guess Windows PowerShell does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions