Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell Core RuntimeException fix #369

Closed
MathiasMagnus opened this issue Jan 16, 2017 · 1 comment
Closed

PowerShell Core RuntimeException fix #369

MathiasMagnus opened this issue Jan 16, 2017 · 1 comment

Comments

@MathiasMagnus
Copy link

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.

@rkeithhill
Copy link
Collaborator

rkeithhill commented Jan 16, 2017

@MathiasMagnus Thanks for the report. This issue has already been fixed and is waiting on the 0.7.0 release.

If you'd like to test this, you could clone this repo and try importing the module from the clone dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants