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

The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception. #2136

Closed
tadyshev opened this issue Oct 9, 2018 · 35 comments

Comments

@tadyshev
Copy link
Contributor

tadyshev commented Oct 9, 2018

Description

Fake is failing to build a solution.

Expected behavior

Should build the solution successfully.

Actual behavior

Fails to build with this stack trace

Script reported an error:
-> BuildFailedException: Target 'Build' failed.
   StackTrace:
        at Fake.Core.TargetModule.runInternal(Boolean singleTarget, Int32 parallelJobs, String targetName, FSharpList`1 args) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 654
        at Fake.Core.TargetModule.runWithDefault$cont@795-1(Boolean allowArgs, FSharpFunc`2 fDefault, FSharpMap`2 results, Unit unitVar) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 827
        at <StartupCode$build_4906E2CE501699898D255247ED6E2EF3DFC4C65D1AB60B8673D7ECAB2D0EA136>.$Build$fsx.main@() in C:\Users\$SOME_PRIVATE_PATH\build.fsx:line 234
-> One or more errors occurred. (The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.)
-> TypeInitializationException: The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.
   StackTrace:
        at Fake.Core.Process.getRedirectOutputToTrace() in D:\a\1\s\src\app\Fake.Core.Process\Process.fs:line 339
        at Fake.DotNet.MSBuild.build(FSharpFunc`2 setParams, String project) in D:\a\1\s\src\app\Fake.DotNet.MSBuild\MSBuild.fs:line 480
        at Build.msbuild(String target, IEnumerable`1 projects) in C:\Users\$SOME_PRIVATE_PATH\build.fsx:line 40
        at [email protected](TargetParameter unitVar) in C:\Users\$SOME_PRIVATE_PATH\build.fsx:line 159
        at Fake.Core.TargetModule.runSimpleInternal(TargetContext context, Target target) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 196
-> NotSupportedException: The given path's format is not supported.

Known workarounds

N/A

Related information

  • Operating system: Windows 10
  • .NET Runtime, CoreCLR or Mono Version: .NET Core SDK 2.1.402
  • Version of FAKE (4.X, 5.X) 5.X
@matthid
Copy link
Member

matthid commented Oct 9, 2018

Interesting 'NotSupportedException'... Can you give some way or a minimal script to reproduce this?

@tadyshev
Copy link
Contributor Author

Building Fake with dotnet build build.proj reproduces the exception, with commit 40bf083.

@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi It doesn't either for me nor for the build-server so something needs to be different on your system. Are you using a special shell or something like that?

@BlythMeister
Copy link
Contributor

@ditadi are you able to upload the entire build output rather than just the error. It looks like something being passed to msbuild is busted, fake logs the call to msbuild before it runs complete with all the args.

@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi Ah and can you report in which directory the source are cloned? Maybe it has something to do with some special character in your directory (you can send that private via mail if you don't want to make that public for example matthi.d at gmail.com ).

Some other options are fake -v build (verbose mode) and the full logs (but they are a bit nasty to cleanup).

What's interesting is that there is no stack for the notsupportedexception, which makes this a bit nasty to find... One other option would be to start this in the debugger (via vscode for example). I can help if you have trouble building (as fake doesn't work you need to use dotnet build) or setting up the debugger in code.

@BlythMeister
Copy link
Contributor

I think the not supported exception is coming from msbuild...

@BlythMeister
Copy link
Contributor

I've seen this sort of thing before when the generated path for the project being passed to msbuild is invalid...when I had it, it was all because of the current directory as a lot of things are relative to that.

@tadyshev
Copy link
Contributor Author

tadyshev commented Oct 10, 2018

I cloned FAKE repo to C:\code directory. I added -v flag to <Exec IgnoreStandardErrorWarningFormat="true" Command='dotnet fake -v build $(FakeParallel) $(FakeTargetArg)' WorkingDirectory="$(RepoRootDir)" /> and ran the command dotnet build build.proj and here is the output with that error.

This is noteworthy:
DownloadPaket 00:00:00.0150632 (The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.)

@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi after looking through the code again. This is quite a shot into the dark but can you tell us the following environment variables:

  • PATH (or any other casing of it)
  • PATHEXT
  • MONO (if it exists)

Also can you try to run a script with fake containing the following code (or add it to the build.fsx on top):

Fake.Core.Process.tryFindTool("MONO", "mono")

And I still don't get why there is no stack for this exception, but I can figure that out once we can reproduce this.

@tadyshev
Copy link
Contributor Author

Here is my PATH and PATHEXT. I do not have MONO installed but I tried adding
Fake.Core.Process.tryFindTool("MONO") and Fake.Core.Process.tryFindTool("mono") to the build.fsx file and got the same exception.

@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi Ah now we are slowly getting somewhere, so you are using cygwin as shell, does the same happen when using cmd/powershell or git bash?

@matthid
Copy link
Member

matthid commented Oct 10, 2018

Additionally there is harp:/cygdrive/c/Users/user/AppData/Local/Microsoft/WindowsApps::/Program (ie an empty path)

@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi I tried but I still cannot reproduce. I'm not sure what else to ask for, I guess we need to use the debugger on your machine or customized builds to debug this on your machine

@tadyshev
Copy link
Contributor Author

I ran these commands in cmd and powershell but Cygwin was installed. I removed Cygwin from my machine and I'm still getting the error. Here is a link to my updated PATH.

How would I go about debugging with say Code?

matthid added a commit that referenced this issue Oct 10, 2018
@matthid
Copy link
Member

matthid commented Oct 10, 2018

@ditadi I just pushed some debugger settings (so please git pull) so now you should be able to just open code and then:
image

Note that if you enable "break on all exception" you should eventually see the NotSupportedException and hopefully the stack trace.

There is only one problem: As we use the NuGet package, breakpoints in places like Fake.Core.Process will not work, to make them work you'd need to create a local package and update your script to use it (which is arguably a bit more complicated).

The debugging process is documented a bit here: https://fake.build/fake-debugging.html
The way to use a "local" package is documented here: https://fake.build/contributing.html#A-note-on-module-testing

Let me know if you need further help

@matthid
Copy link
Member

matthid commented Oct 10, 2018

I do not have MONO installed but I tried adding
Fake.Core.Process.tryFindTool("MONO") and Fake.Core.Process.tryFindTool("mono") to the build.fsx file and got the same exception.

Sorry my code was wrong it should read Fake.Core.Process.tryFindTool "MONO" "mono" (it is important to have both arguments as otherwise nothing happens, besides fake issuing a warning). What I hoped is that the error report show a different stacktrace

@matthid
Copy link
Member

matthid commented Oct 10, 2018

Ah one more thing: Can you try other installation methods of fake besides using dotnet-fake? We have a list here in particular chocolatey or the dotnet tool install -g fake-cli methods would be interesting as they use a different packaging (you can always verify which installation you run with fake --version which prints the path to the dll)

@tadyshev
Copy link
Contributor Author

I did get a different output when adding updated tryFindTool line. I'll follow the debugging steps when I have more time.

@matthid
Copy link
Member

matthid commented Oct 10, 2018

That is basically jackpot, now all we need to to is copy (inline) the code for the function into your script and add some printf to see which variables are the problem. I'll send the code for this tommorow, just wanted to let you know that debugging might not be required after all

@tadyshev
Copy link
Contributor Author

I ended up attempting to re-create the issue on a fresh machine and couldn't do it. I decided to nuke my machine that had this problem and start with fresh install of Windows 10. I am no longer experiencing this issue with two new machines I've set up.

@matthid
Copy link
Member

matthid commented Oct 11, 2018

Oh no, I'd have liked to figure out the root cause, but I'm glad it works for you

I'd assume it had to do with some environment variable or something like that...

I guess this means all I can do is add sone code to improve the error message in case this happens again, but we cannot fix the root cause

@matthid
Copy link
Member

matthid commented Oct 12, 2018

Next time the error message will tell us what the problem is. Additionally I figured out why the stacktrace was missing and fixed that as well

@matthid matthid mentioned this issue Oct 12, 2018
BlythMeister pushed a commit to BlythMeister/FAKE that referenced this issue Oct 13, 2018
matthid pushed a commit that referenced this issue Oct 13, 2018
* Add message to the build state update

* Update Fake.Tools.Pickles and added Unit tests

* Fix Tests

* Fix ArgumentHelper.checkIfMono

* Made checkIfMono a bit more elegant

* Correct publish artifact

* Add `CreateProcess.disableTraceCommand` and use it to hide `appveyor.exe` calls.

* print all stack traces in verbose mode, references #2136

* next time we can fix #2136

* add BlackFox.Fake.BuildTask to docs /cc @vbfox

* Docs & cleanup

* more docs

* documentation
@panesofglass
Copy link
Contributor

I just had this pop up on local and AppVeyor builds. It fails almost immediately after attempting to run the BuildVersion task which simply tries to update the AppVeyor build version using the Fake.BuildServer.AppVeyor.updateBuild function:

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target             Duration
------             --------
BuildVersion       00:00:00.0395591   (The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.)
CleanBin           00:00:00           (skipped)
AssemblyInfo       00:00:00           (skipped)
Build              00:00:00           (skipped)
Xdt                00:00:00           (skipped)
UnitTests          00:00:00           (skipped)
IntegrationTests   00:00:00           (skipped)
Zip                00:00:00           (skipped)
Test               00:00:00           (skipped)
Pack               00:00:00           (skipped)
All                00:00:00           (skipped)
Total:             00:00:00.2228115
Status:            Failure
---------------------------------------------------------------------
dotnet : Script reported an error:
At C:\projects\thermion\init.ps1:54 char:1
+ dotnet fake build --target $Target
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Script reported an error::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
-> BuildFailedException: Target 'BuildVersion' failed.
-> One or more errors occurred. (The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.)
-> TypeInitializationException: The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception.
-> Error while trying to find files like 'mono.COM' in path '[System.IO.Path]::GetDirectoryName' (replaced '[System.IO.Path]::GetDirectoryName'). Please report this issue to FAKE and reference 
https://github.com/fsharp/FAKE/issues/2136.
-> NotSupportedException: The given path's format is not supported.
Hint: To further diagnose the problem you can run fake in verbose mode `fake -v run ...` or set the 'FAKE_DETAILED_ERRORS' environment variable to 'true'
Performance:
 - Cli parsing: 429 milliseconds
 - Packages: 15 milliseconds
 - Script analyzing: 28 milliseconds
 - Script running: 521 milliseconds
 - Script cleanup: 1 millisecond
 - Runtime: 1 second
Error executing: fake build --target All

Locally, I see the same error in the Build step when it tries to run MSBuild.

I can run successfully using the fake-cli I installed globally but not using the dotnet restore build.proj && dotnet fake build --target All approach.

@matthid
Copy link
Member

matthid commented Jan 12, 2019

@panesofglass you can run with verbose flag fake -v to get the stack traces. But from the error messages I'd assume something is failing in your powershell script and somehow the string "[System.IO.Path]::GetDirectoryName" escaped into an environment variable (when I'd assume you tried to get the directory name of something instead)

@matthid
Copy link
Member

matthid commented Jan 13, 2019

@panesofglass if this isn't an error in the Powershell script please open a new issue which makes it easier to track & discuss

@panesofglass
Copy link
Contributor

I'll open a new issue as soon as I have time to get more info.

@panesofglass
Copy link
Contributor

I found that when I run FAKE 5 in PowerShell 5, I see the above error. In PowerShell 6, I do not. Workaround is to use PowerShell 6.

@matthid
Copy link
Member

matthid commented Jun 27, 2019

I still think this is specific to how you call fake in you poweshell script. I guess you are using a powershell 6 only feature...

@panesofglass
Copy link
Contributor

Well, looks like this is happening again even in PowerShell 6:

Could not detect msbuild version from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe': System.TypeInitializationException: The type initializer for '<StartupCode$Fake-Core-Process>.$Process' threw an exception. ---> System.Exception: Error while trying to find files like 'mono.COM' in path '[System.IO.Path]::GetDirectoryName' (replaced '[System.IO.Path]::GetDirectoryName'). Please report this issue to FAKE and reference https://github.com/fsharp/FAKE/issues/2136. ---> System.NotSupportedException: The given path's format is not supported.
   at System.IO.Path.GetFullPath(String path)
   at System.IO.DirectoryInfo..ctor(String path)
   at [email protected](String path) in d:\a\1\s\src\app\Fake.Core.Process\ProcessUtils.fs:line 26
   --- End of inner exception stack trace ---
   at [email protected](String path) in d:\a\1\s\src\app\Fake.Core.Process\ProcessUtils.fs:line 33
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& curr)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.Internal.IEnumerator.next@187[T](FSharpFunc`2 f, IEnumerator`1 e, FSharpRef`1 started, Unit unitVar0)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.filter@182.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.oneStepTo@980[T](IEnumerable`1 source, List`1 prefix, FSharpRef`1 enumeratorR, Int32 i)
   at Microsoft.FSharp.Collections.SeqModule.action@4268-1[T](IEnumerable`1 source, List`1 prefix, FSharpRef`1 enumeratorR, Int32 i, Unit unitVar0)
   at [email protected](Int32 i)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.unfold@199.DoMoveNext(b& curr)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Core.CompilerServices.RuntimeHelpers.takeInner@267[T,TResult](ConcatEnumerator`2 x, Unit unitVar0)
   at Microsoft.FSharp.Collections.Generator.Microsoft-FSharp-Collections-Generator-Generator-1-get_Apply@412-1.Invoke(Unit unitVar0)
   at Microsoft.FSharp.Collections.Generator.appG[a](Generator`1 g)
   at Microsoft.FSharp.Collections.Generator.Microsoft-FSharp-Collections-Generator-Generator-1-get_Apply@335.Invoke(Unit unitVar0)
   at Microsoft.FSharp.Collections.Generator.appG[a](Generator`1 g)
   at Microsoft.FSharp.Collections.Generator.EnumeratorWrappingLazyGenerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.TryHead[T](IEnumerable`1 source)
   at <StartupCode$Fake-Core-Process>.$Process..cctor() in d:\a\1\s\src\app\Fake.Core.Process\Process.fs:line 909
   --- End of inner exception stack trace ---
   at Fake.Core.Process.execRaw(FSharpFunc`2 configProcessStartInfoF, TimeSpan timeOut, Boolean silent, FSharpFunc`2 errorF, FSharpFunc`2 messageF) in d:\a\1\s\src\app\Fake.Core.Process\Process.fs:line 597
   at Fake.Core.Process.execWithResult(FSharpFunc`2 configProcessStartInfoF, TimeSpan timeOut) in d:\a\1\s\src\app\Fake.Core.Process\Process.fs:line 612
   at [email protected](String args) in d:\a\1\s\src\app\Fake.DotNet.MSBuild\MSBuild.fs:line 825
   at Fake.DotNet.MSBuild.getFromCall@690(String exePath, FSharpFunc`2 callMsbuildExe, Unit unitVar0) in d:\a\1\s\src\app\Fake.DotNet.MSBuild\MSBuild.fs:line 692
msbuild version '13.0.0.0' doesn't support binary logger, please set the msbuild argument 'DisableInternalBinLog' to 'true' to disable this warning.

@matthid
Copy link
Member

matthid commented Jun 28, 2019

@panesofglass please try to provide a minimal repro. I'm still convinced this is an issue in your powershell code...

@panesofglass
Copy link
Contributor

I switched to a build project rather than using the scripts. That approach continues to be the most consistently working approach and lets me use System.Data.SqlClient, so this is fine to remain closed.

@drk-mtr
Copy link

drk-mtr commented Nov 18, 2019

Same issue here. Relevant output from fake -v build -t run:

Script reported an error:
-> TypeInitializationException: The type initializer for '<StartupCode$Fake-Core-Target>.$Target' threw an exception.
   StackTrace:
        at Fake.Core.TargetModule.initAndProcess[a](FSharpFunc`2 proc) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 1099
        at <StartupCode$build_F86F55EA9BC1A1038F7FA41FCA9707BB8E9F555FAFF2335693F841592C7DDE89>.$Build$fsx.main@() in C:\Projects\Kartel\build.fsx:line 18     
-> MissingMethodException: Method not found: 'Microsoft.FSharp.Control.FSharpAsync`1<!!0[]> Microsoft.FSharp.Control.FSharpAsync.Parallel(System.Collections.Generic.IEnumerable`1<Microsoft.FSharp.Control.FSharpAsync`1<!!0>>, Microsoft.FSharp.Core.FSharpOption`1<Int32>)'.
   StackTrace:
        at Fake.Core.CommandLineParsing.OptionsParser.Parse(IEnumerable`1 optionStrings')
        at <StartupCode$Fake-Core-CommandLineParsing>[email protected](OptionSection oStrs) in D:\a\1\s\src\app\Fake.Core.CommandLineParsing\docopt.fs\Docopt\Docopt.fs:line 85
        at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& curr)
        at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
        at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
        at Fake.Core.Docopt..ctor(String doc', FSharpOption`1 soptChars') in D:\a\1\s\src\app\Fake.Core.CommandLineParsing\docopt.fs\Docopt\Docopt.fs:line 83  
        at <StartupCode$Fake-Core-Target>.$Target..cctor() in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 28

The same repo works on my Windows 10 PC, my Windows Subsystem for Linux running Ubuntu, and my friend's Linux PC (unsure on distro/kernel etc). It's failing on my other Windows 10 PC as above. From what I can tell I have the correct dotnet core versions installed (3.0.100) and I'm completely stuck here - tried deleting paket.lock and .paket and .fake but to no avail.

I realise my message is far from helpful as it doesn't contain a minimal repro so apologies for that. The task of creating a minimal repro is a rather mammoth one because there is a huge mix of C# and F# projects in this solution so it'll take me a while to unpick!

The relevant line (18) in build.fsx is Target.initEnvironment ().

@matthid
Copy link
Member

matthid commented Nov 18, 2019

@drk-mtr I think your problem is FSharp.Core update (ie using a newer one than bundled with fake). Just update your fake runner. If not please open a new issue with more details.

@drk-mtr
Copy link

drk-mtr commented Nov 18, 2019

Quite right! A paket update resolved this. Thanks for the lightning fast response, and for replying despite the fact that I was silly enough to post without trying that first!

I think it's down to my misunderstanding of paket. I had assumed that versions were pinned and would therefore be the same on each system due to the paket.lock. So I had tried pinning F# to 4.6 and updating with dotnet tool update -g fake-cli, but had assumed nuget package versions were "known good" - I'll need to read up. Thanks again!

@teyc
Copy link

teyc commented Feb 5, 2020

In my case I had an old version of fake. To resolve it:

dotnet tool update -g fake-cli

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

No branches or pull requests

6 participants