Fsharp: FSI 4.1 won't start; fails to load System.Runtime 4.1.0.0 (and a bunch of other stuff)

Created on 4 Jun 2017  路  23Comments  路  Source: dotnet/fsharp

I've installed F# 4.1 through the Visual Studio 2017 installer, and FSI won't start. Instead, it shows the following message and crashes:

PS C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0> ./fsi
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly
'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
   at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain(String[] argv)

Repro steps

Provide the steps required to reproduce the problem

  1. Install the "F# Language Support" component through the Visual Studio 2017 installer. (I'm using VS 2017 Enterprise, no idea if it matters)

  2. Open PowerShell and go to the installation directory for F#.

  3. Run ./fsi

Expected behavior

F# Interactive shows a welcome message and a prompt.

Actual behavior

The executable crashes.

Related information

I've made a dump of the fusion logs here: https://drive.google.com/open?id=0B-EzQ3qbRJtvUXlDay04WXBiX3c

There are a number of failed assembly bindings there:

  • System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.IO, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Linq, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Linq.Expressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Runtime.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Threading.Thread, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  • System.Threading.ThreadPool, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Other troubleshooting attempts that have not led anywhere:

  • I uninstalled F# from the VS installer, made sure the directory was gone, and re-installed. No difference in behavior.
  • I had an installation of F# 4.0, where FSI started as expected. Removing that did not help making F# 4.1 start.
  • I uninstalled all .NET Core versions, to no avail.

For reference, here's the SO question where I was recommended to file an issue here: https://stackoverflow.com/questions/44332029

Operating system: Windows 10 Pro, with Creators Update

Area-FSI Area-Setup Severity-Medium bug

All 23 comments

This is odd as this works just fine for me.

@KevinRansom The Binding to System.Runtime doesn't necessarily mean this is the .NET Core version of fsi.exe - that can still be a .NET Framework component using the facade assemblies. I don't think.NET Core is actually relevant here

I wonder if the correct version of .NET Framework support is not properly installed on this machine. Is Visual Studio running correctly?

I am pretty certain this is a set of coreclr binaries. If it was the desktop FSI then it would try and succeed in loading mscorlib.dll. Not System.Runtime.dll.

Kevin

@tlycken
Hi, I guess we need to grab some more information.

  1. What happens if you run at the dos prompt, I.e. not from powershell.
  2. What does where fsi.exe show.
    image

  3. what is the size and file version of the fsi.exe and fsharp.core that you execute
    you can see file version of the details page on properties using file explorer

image

Thanks

Kevin

@KevinRansom Thanks for looking into this. CMD session:

C:\Users\tomas>where fsi.exe
INFO: Could not find files for the given pattern(s).

C:\Users\tomas>cd "c:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0"

c:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0>where fsi.exe
c:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsi.exe

c:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0>fsi.exe
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain(String[] argv)

I seem to have a later file version than yours:

fsi.exe details

I see this behavior with and without .NET Core installed.

And no, Visual Studio doesn't seem to work either; trying to create a new F# project, I got the following error about the FSharpProjectPackage failing to load, and then was taken back to the start page.

trying to create a new F# library

At the bottom of the indicated log file, is this:

  <entry>
    <record>498</record>
    <time>2017/06/07 06:52:44.138</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>CreateInstance failed for package [FSharpProjectPackage]Source: &apos;mscorlib&apos; Description: Exception has been thrown by the target of an invocation.&#x000D;&#x000A;System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.IO.FileNotFoundException: Could not load file or assembly &apos;System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&apos; or one of its dependencies. The system cannot find the file specified.&#x000D;&#x000A;   at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpProjectPackage..ctor()&#x000D;&#x000A;   --- End of inner exception stack trace ---&#x000D;&#x000A;   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)&#x000D;&#x000A;   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)&#x000D;&#x000A;   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)&#x000D;&#x000A;   at System.Activator.CreateInstance(Type type, Boolean nonPublic)&#x000D;&#x000A;   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark&amp; stackMark)&#x000D;&#x000A;   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)&#x000D;&#x000A;   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)&#x000D;&#x000A;   at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)System.IO.FileNotFoundException: Could not load file or assembly &apos;System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&apos; or one of its dependencies. The system cannot find the file specified.&#x000D;&#x000A;File name: &apos;System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&apos;&#x000D;&#x000A;   at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpProjectPackage..ctor()&#x000D;&#x000A;&#x000D;&#x000A;Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll&#x000D;&#x000A;Running under executable  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe&#x000D;&#x000A;--- A detailed error log follows. &#x000A;&#x000D;&#x000A;=== Pre-bind state information ===&#x000D;&#x000A;LOG: DisplayName = System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#x000A; (Fully-specified)&#x000D;&#x000A;LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/common7/ide/&#x000D;&#x000A;LOG: Initial PrivatePath = NULL&#x000D;&#x000A;Calling assembly : FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.&#x000D;&#x000A;===&#x000D;&#x000A;LOG: This bind starts in default load context.&#x000D;&#x000A;LOG: Using application configuration file: C:\Users\tomas\AppData\Local\Microsoft\VisualStudio\15.0_b6723a42\devenv.exe.config&#x000D;&#x000A;LOG: Using host configuration file: &#x000D;&#x000A;LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.&#x000D;&#x000A;LOG: The same bind was seen before, and was failed with hr = 0x80070002.&#x000D;&#x000A;</description>
    <guid>{91A04A73-4F2C-4E7C-AD38-C1A68E7DA05C}</guid>
    <hr>80004005 - E_FAIL</hr>
    <errorinfo></errorinfo>
  </entry>

Quite a mouthful, but it boils down to the same FileNotFoundException for System.Runtime 4.1.0.0.

If there's anything else I can help with, please let me know.

I am pretty certain this is a set of coreclr binaries. If it was the desktop FSI then it would try and succeed in loading mscorlib.dll. Not System.Runtime.dll.

But how one would even get the CoreCLR compiler binaries through the Visual Studio installer? My understanding is that they aren't even used in the installation as yet.

@tlycken I really don't understand this one :)

Have you ever built http://github.com/Microsoft/visualfsharp on this machine?

Have you previously installed any versions of ,NET Core on this machine, and could there be some relic from that involved?

I took a look at the fusion logs and the attempts to bind to System.Runtime 4.1.0.0 look wrong. But the size and ILDASM of fsi,exe look like they are the .NET Framework version of that component.

@dsyme That makes (at least) two of us :)

Have you ever built http://github.com/Microsoft/visualfsharp on this machine?

No.

Have you previously installed any versions of ,NET Core on this machine, and could there be some relic from that involved?

Yes; uninstalling them were part of my troubleshooting here, but of course there could have been some relics left behind still screwing up the results. I have now re-installed the version that comes with Visual Studio 2017, since uninstalling did not change anything.

@tlycken Could you try building this repo "build net40" then running "releasenet40binfsi,exe" please? That might give us an indication if it is the state of your machine or the F# bits.

Just a thought. I really have no idea. Your F# bits look fine

Sigh!!! I hate install issues.

So ... it's probably best to blow everything away.

1: Uninstall Visual Studio
2: Delete: C:Program Files (x86)Microsoft SDKsF#
3: Delete: C:Program Files (x86)Reference AssembliesMicrosoftFSharp
4: C:UsersAppDataLocalMicrosoftVisualStudio
5: Edit the Path environment variable to remove anything pointing at F#

I doubt if removing the registry stuff is necessary.

Reboot ... because ... "why not"

Install VS --- select FSharp tools for Visual Studio.

@KevinRansom Haha, at least you didn't ask me to wipe to a clean installation of Windows ;)

I'll try that (and, in addition, remove all F# related extensions from VS Code, just to be safe). If it doesn't work, I'll try building from source as @dsyme suggested, too - but as you say, it seems more likely that this is an issue with my system specifically than that there's something wrong with the F# bits, since none of you can reproduce.

@KevinRansom Resetting everything you suggested did not make a difference 馃槩

@dsyme Actually, the build fails - still failing to find System.Runtime 4.1.0.0. I ran ./build net40 from an administrative PowerShell prompt, and got the attached output.

build-log.txt

@tlycken Can you build from a non-Powershell VS2017 developer prompt?

That's a strange log. Could you also check "gacutil /l FSharp.Core" please?

It feels like you have some strange machine-wide problem, perhaps a machine-wide binding redirect installed or something. Very odd

@dsyme Gacutil seems to show something suspicious:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>gacutil /l FSharp.Core
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  FSharp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
  FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
  FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

Number of items = 3

Here's a build log from the VS2017 dev cmd prompt: build-log.txt

Where should I look for a machine-wide binding-redirect?

@tlycken Yes, I think that 4.4.1.0 FSharp.Core entry in the GAC is wrong. It would be very nice to find out how it got there!

If you're game, try

gacutil /uf "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

Here is the listing on my machine with VS2017 installed:

C:\GitHub\dsyme>gacutil /l FSHarp.Core
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  FSHarp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
  FSHarp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

Number of items = 2

@dsyme Thanks a lot - cleaning up the GAC was the solution!

I can now run FSI with F# 4.1, as well as create new F# projects with dotnet new and Visual Studio (though the latter required a repair and reboot before it worked...).

No idea how F# 4.1.0.0 ended up in the GAC, and I guess we'll never know. Either way, thanks to both of you for helping me fix this!

I'm having the same issue with C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0.
I've installed F# via Visual Studio 2017 Build tools only installer.

C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0>fsi

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f
11d50a3a' or one of its dependencies. The system cannot find the file specified.

   at Sample.Microsoft.FSharp.Compiler.Interactive.Main.MainMain(String[] argv)

C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0>
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools>gacutil /l FSharp
.Core
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
, processorArchitecture=MSIL
  FSharp.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
, processorArchitecture=MSIL
  FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
, processorArchitecture=MSIL
  FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
, processorArchitecture=MSIL
  FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
, processorArchitecture=MSIL

Number of items = 5


I believe FSharp.Compiler.Private is the culprit in this case.

image

So turned out I added FSharp.Compiler.Private to my GAC for some strange reason. This was most likely my own doing. The fsi work again.

@nojaf Glad to hear it!

@nojaf ,

Can you write the steps you took to solve the problem? I have the same error but know nothing about GAC or .NET or ILSpy or anything. I uninstalled vs2015 and now vscode and fsi is giving me the exact same error you showed.

I solved the issue by
1) uninstalling all F# features from vs2017
2) deleting (and all subfolders) C:Program Files (x86)Microsoft SDKsF#
3) restarting the computer
4) installing the f# features of vs2017

Thank you all for your work on this thread.

Was this page helpful?
0 / 5 - 0 ratings