Skip to content

Crash when upgrading to FSharp.Formatting 1.4.0.4 #337

Closed

Description

@eiriktsarpalis

I came across the following crash when upgrading FSharp.Formatting in the mbrace-docs repository:

Generating 'c:\Users\eirik\Development\mbrace\mbrace-docs\docs\tools\..\content/azure-tutorial.html'
System.MethodAccessException: Attempt by method 'FSharpVSPowerTools.Lexer.|GenericTypeParameterPrefix|StaticallyResolvedTypeParameterPrefix|Other|@92(System.String, Microsoft.FSharp.Compiler.SourceCodeServices.FSharpTokenInfo)' to access method 'Microsoft.FSharp.Compiler.Parser.tokenTagToTokenId(Int32)' failed.
   at FSharp.CodeFormat.CodeFormatAgent.ParseSource(String file, String source, FSharpOption`1 options, FSharpOption`1 defines) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.CodeFormat\CodeFormatAgent.fs:line 390
   at FSharp.Literate.ParseScript.parseScriptFile(String file, String content, CompilerContext ctx) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\ParseScript.fs:line 198
   at FSharp.Literate.Literate.ParseScriptFile[d](String path, FSharpOption`1 formatAgent, FSharpOption`1 compilerOptions, FSharpOption`1 definedSymbols, FSharpOption`1 references, FSharpOption`1 fsiEvaluator) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 67
   at FSharp.Literate.Literate.ProcessScriptFile(String input, FSharpOption`1 templateFile, FSharpOption`1 output, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSharpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 fsiEvaluator, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots, FSharpOption`1 generateAnchors, FSharpOption`1 assemblyReferences, FSharpOption`1 customizeDocument) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 167
   at <StartupCode$FSharp-Literate>[email protected](String file, String output) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 184
   at <StartupCode$FSharp-Literate>.$Main.processDirectory@199(FSharpOption`1 format, Boolean processRecursive, FSharpFunc`2 processScriptFile, FSharpFunc`2 processMarkdown, String indir, String outdir) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 218
   at FSharp.Literate.Literate.ProcessDirectory(String inputDirectory, FSharpOption`1 templateFile, FSharpOption`1 outputDirectory, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSharpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 fsiEvaluator, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots, FSharpOption`1 generateAnchors, FSharpOption`1 assemblyReferences, FSharpOption`1 processRecursive, FSharpOption`1 customizeDocument) in c:\Tomas\Public\tpetricek\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 181
   at FSI_0003.processDir@88(String topdir) in c:\Users\eirik\Development\mbrace\mbrace-docs\docs\tools\generate.fsx:line 93
   at FSI_0003.buildDocumentation() in c:\Users\eirik\Development\mbrace\mbrace-docs\docs\tools\generate.fsx:line 85
   at <StartupCode$FSI_0003>.$FSI_0003.main@() in c:\Users\eirik\Development\mbrace\mbrace-docs\docs\tools\generate.fsx:line 105
Stopped due to error

Activity

  1. dsyme commented on Sep 10, 2015

    @dsyme
    Contributor

    FCS 1.4.0.4 is not binary compatible with previous versions because some things have been made internal. FSharp.Formatting uses a version constraint ">= 0.0.87" for FCS which is inherently dangerous since binary compat has never really been promised for FCS. I think a constraint ">= 0.0.87" and "<= 1.3.0.2" will work OK though in practice

  2. tpetricek commented on Sep 10, 2015

    @tpetricek
    Member

    I guess we should just update FSharp.Formatting to use the latest version then. But we are also relying on Visual F# PowerTools, so we might need to wait for them first...

    In the meantime, is there a way to specify range in a nuspec file?

  3. dsyme commented on Sep 10, 2015

    @dsyme
    Contributor

    Note 1.4 is for F# 4.x support. That might not be what you want when processing scripts as it may induce dependencies on having FSHarp.Core 4.4.0.0 available, at least check for that. (The default behaviour should be to look at the FSharp.Core referenced by the ultimate host .EXE of the DLL, which sounds sensible, but be careful!)

  4. tpetricek commented on Sep 12, 2015

    @tpetricek
    Member

    I see, didn't realize this is for F# 4.x. I'm testing a fix (specifying range in the NuGet package)

  5. tpetricek commented on Sep 12, 2015

    @tpetricek
    Member

    Ok, new version of F# formatting fixes this, but there is a big but....

    If you are using Paket, you need to explicitly tell it that you want at least the current version of F# Formatting:

    nuget FSharp.Formatting >= 2.10.3
    

    As we did not have the constraint before, there is another valid resolution which is to get the latest F# Compiler Service and older release of F# Formatting. This will not work - but I think there is no way to prevent this - because the new incompatible version of FCS has a higher version :-(

  6. tpetricek commented on Sep 12, 2015

    @tpetricek
    Member

    Actually, maybe you only run into the issues if you also explicitly require FCS, which was the case in my project, which had:

    nuget FSharp.Compiler.Service
    nuget FSharp.Formatting >= 2.10.3
    

    So, this should be OK for normal uses...

  7. CumpsD commented on Oct 13, 2015

    @CumpsD

    I am resolving into this:

        FSharp.Compiler.Service (0.0.90)
        FSharp.Formatting (2.11.0)
          FSharp.Compiler.Service (>= 0.0.90 <= 1.3)
          FSharpVSPowerTools.Core (1.9.0)
        FSharpVSPowerTools.Core (1.9.0)
          FSharp.Compiler.Service (>= 0.0.90)
    

    However I am still getting the same error

    System.MethodAccessException: Attempt by method 'FSharpVSPowerTools.Lexer.|GenericTypeParameterPrefix|StaticallyResolvedTypeParameterPrefix|Other|@92(System.String, Microsoft.FSharp.Compiler.SourceCodeServices.FSharpTokenInfo)' to access method 'Microsoft.FSharp.Compiler.Parser.tokenTagToTokenId(Int32)' failed.
       at FSharp.CodeFormat.CodeFormatAgent.ParseSource(String file, String source, FSharpOption`1 options, FSharpOption`1 defines) in c:\Projects\FSharp.Formatting\src\FSharp.CodeFormat\CodeFormatAgent.fs:line 388
       at FSharp.Literate.ParseScript.parseScriptFile(String file, String content, CompilerContext ctx) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\ParseScript.fs:line 198
       at FSharp.Literate.Literate.ParseScriptFile[d](String path, FSharpOption`1 formatAgent, FSharpOption`1 compilerOptions, FSharpOption`1 definedSymbols, FSharpOption`1 references, FSharpOption`1 fsiEvaluator) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 67
       at FSharp.Literate.Literate.ProcessScriptFile(String input, FSharpOption`1 templateFile, FSharpOption`1 output, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSharpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 fsiEvaluator, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots, FSharpOption`1 generateAnchors, FSharpOption`1 assemblyReferences, FSharpOption`1 customizeDocument) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 167
       at <StartupCode$FSharp-Literate>[email protected](String file, String output) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 184
       at <StartupCode$FSharp-Literate>.$Main.processDirectory@199(FSharpOption`1 format, Boolean processRecursive, FSharpFunc`2 processScriptFile, FSharpFunc`2 processMarkdown, String indir, String outdir) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 218
       at FSharp.Literate.Literate.ProcessDirectory(String inputDirectory, FSharpOption`1 templateFile, FSharpOption`1 outputDirectory, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSharpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 fsiEvaluator, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots, FSharpOption`1 generateAnchors, FSharpOption`1 assemblyReferences, FSharpOption`1 processRecursive, FSharpOption`1 customizeDocument) in c:\Projects\FSharp.Formatting\src\FSharp.Literate\Main.fs:line 181
       at FSI_0003.buildDocumentation() in D:\Code\GH-Exira\ges\docs\tools\generate.fsx:line 140
       at <StartupCode$FSI_0003>.$FSI_0003.main@() in D:\Code\GH-Exira\ges\docs\tools\generate.fsx:line 147
    

    What do I exactly need to do to fix this?

  8. forki commented on Oct 13, 2015

    @forki
    Member

    not sure, but would releasing #345 help?

  9. CumpsD commented on Oct 13, 2015

    @CumpsD

    @forki perhaps, if I ran with this it worked:

    nuget FSharp.Formatting 2.8.0
    nuget FSharpVSPowerTools.Core 1.7.0
    

    but I wanted to upgrade FSharp.Formatting :)

  10. forki commented on Oct 13, 2015

    @forki
    Member

    yeah but paket can't do magic. if stuff is in compatible we need to express this in the dependencies.

  11. CumpsD commented on Oct 13, 2015

    @CumpsD

    Does this issue need to be reopened then? Since the current dependencies actually don't work?

  12. forki commented on Oct 13, 2015

    @forki
    Member

    Yes it's breaking other things too. Like fsreveal
    On Oct 13, 2015 7:39 PM, "David Cumps" [email protected] wrote:

    Does this issue need to be reopened then? Since the current dependencies
    actually don't work?

    —
    Reply to this email directly or view it on GitHub
    #337 (comment)
    .

  13. 30 remaining items

  14. tpetricek commented on Oct 18, 2015

    @tpetricek
    Member

    Thanks everyone for going through the additional test cases. Now I'm really puzzled what change in FAKE is doing this...

    I tried printing the version of FCS loaded in current AppDomain in FAKE 4.5.4 and it still prints the 1.4 version of FCS (but then it works....)

  15. matthid commented on Oct 18, 2015

    @matthid
    Member
    • If you download FsLab journal template, then things will work.
    • But if you download it and change this line to require FAKE 4.5.5 rather than 4.5.4, then things break (on my machine at least).

    Can confirm but not explain this ...

    Maybe FAKE.exe runs in a security context where it is allowed to access internal methods, that would at least explain how it can sometimes work at all... Maybe the context sometimes changes depending on how assemblies are build (the only difference in 4.5.4 and 4.5.5 is adding groups and paket update fsprojects/FAKE@4.5.4...4.5.5)

    To close this issue we should release a version compatible with latest FAKE (ie update to powertools 2.1.0 and latest Fsharp.Compiler.Service)

    The only safe option to prevent this error for now are (at least as far as I can understand this currently):

    • Tell people to either upgrade FSharp.Formatting
    • Downgrade FAKE to version 3

    Maybe we should somehow detect a valid fake version and fail early if we are not compatible?

  16. tpetricek commented on Oct 18, 2015

    @tpetricek
    Member

    Yeah, we should definitely update F# Formatting to latest versions.. but I would still like to understand why this is happening.

    Looks like there was no relevant change in FAKE, so perhaps this is something that has been caused by an update of FCS from version 1.4.0.1 to version 1.4.0.6. Perhaps there was some change there that affected how assemblies are loaded in FSI evaluator....?

  17. tpetricek commented on Oct 18, 2015

    @tpetricek
    Member

    Looks like FCS does not have a tag on GitHub for 1.4.0.1, but here are the changes between 1.4.0.2 and 1.4.0.6: fsharp/fsharp-compiler-docs@1.4.0.2...1.4.0.6

  18. added a commit that references this issue on Oct 18, 2015
    c9bae27
  19. matthid commented on Oct 18, 2015

    @matthid
    Member

    but I would still like to understand why this is happening.

    definitely...

    1.4.0.3 was the first version where the methods where made internal (https://github.com/fsharp/FSharp.Compiler.Service/blob/master/RELEASE_NOTES.md#1403--). This is what @dsyme was mentioning on his first post. So I think that's the solution to the mystery? It works until FAKE-4.5.4 because it uses FSharp.Compiler.Service < 1.4.0.3 and doesn't work on later versions.
    Funny change for a patch level version number increase :).

    However this bug also shows that locking our versions in the package doesn't really solve anything for us when running within FAKE. Maybe we should figure out a way to solve this eventually, when we are hit by this again (Spawning our own AppDomain?).

  20. tpetricek commented on Oct 18, 2015

    @tpetricek
    Member

    Ah, I see... so really, when running inside FAKE, we always end up running against the FAKE version of F# Compiler Service... Well that's a bummer.

    I guess that's what @forki was trying to solve by internalizing F# Compiler Service, so that we can load our own version.

    This is all a bit silly, but at least I get it now :)

  21. matthid commented on Oct 18, 2015

    @matthid
    Member

    Another idea would be to move FSharp.Formatting from the build into the main dependency group of FAKE, this would ensure that FAKE is updating FSharp.Compiler.Service only when we update it here.

    @forki would you accept such a change in FAKE? That's not really in the spirit of paket groups and FSharp.Formatting is not a dependency of FAKE AND most important other projects can't really do the same (it is not the correct solution but a hack imho)

    Edit: It's ironic that this couldn't happen before introducing paket groups :)

  22. added a commit that references this issue on Oct 18, 2015
    270a5e5
  23. tpetricek commented on Oct 18, 2015

    @tpetricek
    Member

    Wait - I'm not sure I understand - how is this related to Paket groups? (I thought the issue is just that FAKE comes with FCS and now it happens to come with one that's not compatible with F# Formatting...)

  24. forki commented on Oct 19, 2015

    @forki
    Member

    Yes, but by putting fsf into the main group FAKE's own dependency file
    would work. Then paket would resolver a FCS that is compatible to fsf. And
    we would ship that version with FAKE.
    On Oct 18, 2015 21:41, "Tomas Petricek" [email protected] wrote:

    Wait - I'm not sure I understand - how is this related to Paket groups? (I
    thought the issue is just that FAKE comes with FCS and now it happens to
    come with one that's not compatible with F# Formatting...)

    —
    Reply to this email directly or view it on GitHub
    #337 (comment)
    .

  25. forki commented on Oct 19, 2015

    @forki
    Member

    I'm actually ok with that and would accept pr
    On Oct 19, 2015 09:17, "Steffen Forkmann" [email protected] wrote:

    Yes, but by putting fsf into the main group FAKE's own dependency file
    would work. Then paket would resolver a FCS that is compatible to fsf. And
    we would ship that version with FAKE.
    On Oct 18, 2015 21:41, "Tomas Petricek" [email protected] wrote:

    Wait - I'm not sure I understand - how is this related to Paket groups?
    (I thought the issue is just that FAKE comes with FCS and now it happens to
    come with one that's not compatible with F# Formatting...)

    —
    Reply to this email directly or view it on GitHub
    #337 (comment)
    .

  26. matthid commented on Oct 19, 2015

    @matthid
    Member

    I have one more idea: What about adding FAKE as a dependency of FSharp.Formatting? That should work as well and is a better solution imho (as we really do depend on FAKE in the projectscaffold use-case). Ideally we would not add the dependency to the library package and only to a "scripting" package. But it should not do any harm either (an additional download in the worst case). For FAKE it would lead to slower adoption rates for new versions (as everyone needs to wait for a FSF update).

    This solution assumes that people have FSharp.Formatting and FAKE in the same paket group...

  27. forki commented on Oct 19, 2015

    @forki
    Member

    This solution assumes that people have FSharp.Formatting and FAKE in the
    same paket group.
    that's pretty fair assumption.

    2015-10-19 18:01 GMT+02:00 Matthias Dittrich [email protected]:

    I have one more idea: What about adding FAKE as a dependency of
    FSharp.Formatting? That should work as well and is a better solution imho
    (as we really do depend on FAKE in the projectscaffold use-case). Ideally
    we would not add the dependency to the library package and only to a
    "scripting" package. But it should not do any harm either (an additional
    download in the worst case). For FAKE it would lead to slower adoption
    rates for new versions (as everyone needs to wait for a FSF update).

    This solution assumes that people have FSharp.Formatting and FAKE in the
    same paket group...

    —
    Reply to this email directly or view it on GitHub
    #337 (comment)
    .

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions