Skip to content

PowerShell Core RuntimeException fix #369

Closed
@MathiasMagnus

Description

Check the posh-git FAQ first and if your question is not answered, PLEASE fill in these details so that we can help you!

System Details

  • posh-git version: 0.6.1.20160330
  • PowerShell version:
C:\Users\Matty> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
BuildVersion                   3.0.0.0
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
CLRVersion
PSEdition                      Core
PSRemotingProtocolVersion      2.3
GitCommitId                    v6.0.0-alpha.14
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
  • Git version:
C:\Users\Matty> git --version
git version 2.9.2.windows.1
  • Operating system name and version:
posh-git version: 0.6.1.20160330, PSVersion: 6.0.0-alpha, git version 2.9.2.windows.1, OS: Microsoft Windows NT 6.2.9200.0

Issue Description

When loading the module, PS Core complains about line 234 of GitUtils.ps1 containing

[void][Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Process)

that the last argument is not needed (and unkown to PS Core).
Unable to find type [EnvironmentVariableTarget].

At C:\Users\Matty\Documents\PowerShell\Modules\posh-git\0.6.1.20160330\GitUtils.ps1:234 char:67
+ ... EnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Proces ...
+                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (EnvironmentVariableTarget:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

And indeed, according to the docs, there is no last parameter to this function in .Net Core. Changing the line to

[void][Environment]::SetEnvironmentVariable($key, $value<#, [EnvironmentVariableTarget]::Process#>)

solves the issue with the same behavior, as according to the docs, this is the default behavior of the function (setting env var on process scope). Checking for .Net Core version and when detected, calling without last param solves this issue.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions