fsprojects / FSharpLint

Lint tool for F#
https://fsprojects.github.io/FSharpLint/
MIT License
299 stars 73 forks source link

Running on project with TargetFrameworks including `net6.0` fails with: "The exception has been reported." #618

Open Thorium opened 7 months ago

Thorium commented 7 months ago

Trying the tool with one sample:

git clone https://github.com/simontreanor/FunStripe.git
cd FunStripe
cd src
dotnet fsharplint lint FunStripe.fsproj

Expected: Run and produce a lot of issues.

Actual:

Lint failed while analysing FunStripe.fsproj.
Failed with: The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: One or more errors seen during provided type setup)
Stack trace:    at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.Error[b](ErrorLogger x, Exception exn) in D:\workspace\_work\1\s\src\fsharp\ErrorLogger.fs:line 390
   at FSharp.Compiler.CompilerImports.TcImports.ImportTypeProviderExtensions(CompilationThreadToken ctok, TcConfig tcConfig, String fileNameOfRuntimeAssembly, ILScopeRef ilScopeRefOfRuntimeAssembly, FSharpList`1 runtimeAssemblyAttributes, Entity entityToInjectInto, FSharpEvent`1 invalidateCcu, Range m) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1395
   at FSharp.Compiler.CompilerImports.ccuRawDataAndInfos@1566-1.Invoke(Unit unitVar0) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1570
   at FSharp.Compiler.CompilerImports.PrepareToImportReferencedFSharpAssembly@1581.Invoke(Unit unitVar0) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1590
   at Microsoft.FSharp.Primitives.Basics.List.collectToFreshConsTail[T,TResult](FSharpFunc`2 f, FSharpList`1 list, FSharpList`1 cons) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 439
   at Microsoft.FSharp.Primitives.Basics.List.collect[T,TResult](FSharpFunc`2 f, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 447
   at FSharp.Compiler.CompilerImports.k@808-28(TcImports tcImports, FSharpList`1 _arg5) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1672
   at FSharp.Compiler.CompilerImports.RegisterAndImportReferencedAssemblies@1659-4.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1659
   at FSharp.Compiler.CompilerImports.BuildNonFrameworkTcImports@1910-1.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\CompilerImports.fs:line 1910
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@757-237.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 757
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@756-234.Invoke(CancellationToken ct)
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.f@728-103(CompilationGlobalsScope resource, FSharpChoice`2 res)
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@752-229.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 752
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@1028-263.Invoke(CancellationToken ct, FSharpOption`1 _arg1) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 1028
   at Internal.Utilities.Library.Eventually.steps[T](CancellationToken ct, FSharpOption`1 swinfo, Eventually`1 e) in D:\workspace\_work\1\s\src\fsharp\absil\illib.fs:line 913
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@1028-264.Invoke(CancellationToken ct, FSharpOption`1 swinfo) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 1028
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.toCancellableAux@854-4[a](CancellationToken ct, Eventually`1 e)
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@1108-273.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 1108
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.clo@1108-274.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 1108
   at <StartupCode$FSharp-Compiler-Service>.$IncrementalBuild.GetCheckResultsBeforeSlotInProject@1218-1.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\IncrementalBuild.fs:line 1218
   at <StartupCode$FSharp-Compiler-Service>.$Service.ParseAndCheckFileInProject@689-20.Invoke(CancellationToken ct) in D:\workspace\_work\1\s\src\fsharp\service\service.fs:line 689
   at <StartupCode$FSharp-Compiler-Service>.$Reactor.EnqueueAndAwaitOpAsync@220-2.Invoke(CompilationThreadToken ctok) in D:\workspace\_work\1\s\src\fsharp\service\Reactor.fs:line 223
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 337
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInAnotherThread[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 851
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 886
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1148
   at FSharpLint.Framework.ParseFile.parse(String file, String source, FSharpChecker checker, FSharpProjectOptions options) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Framework\ParseFile.fs:line 42
   at FSharpLint.Framework.ParseFile.parseFile(String file, FSharpChecker checker, FSharpOption`1 projectOptions) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Framework\ParseFile.fs:line 73
   at FSharpLint.Application.Lint.parsedFiles@427.Invoke(String file) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 427
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 250
   at FSharpLint.Application.Lint.parseFilesInProject@410(OptionalLintParameters optionalParams, Configuration config, FSharpFunc`2 projectProgress, FSharpFunc`2 warningReceived, FSharpChecker checker, FSharpList`1 files, FSharpProjectOptions projectOptions) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 424
   at FSharpLint.Application.Lint.lintProject$cont@396(OptionalLintParameters optionalParams, String projectFilePath, ToolsPath toolsPath, Unit unitVar) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 442
   at FSharpLint.Application.Lint.lintProject(OptionalLintParameters optionalParams, String projectFilePath, ToolsPath toolsPath) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 395
   at FSharpLint.Console.Program.start(ParseResults`1 arguments, ToolsPath toolsPath) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Console\Program.fs:line 122
Thorium commented 7 months ago

This one is not working in the master branch either.

knocte commented 7 months ago

@Thorium does linting the solution (instead of the project file) yield a different stack trace?

Thorium commented 7 months ago

No it's the same. I found the issue: The project file has: <TargetFrameworks>net6.0;net472;netstandard2.1</TargetFrameworks>

FSharpLint is compiled with net5.0. If I add that to the TargetFrameworks, it works: <TargetFrameworks>net5.0;net6.0;net472;netstandard2.1</TargetFrameworks>

knocte commented 7 months ago

FSharpLint is compiled with net5.0. If I add that to the TargetFrameworks, it works:

Ok thanks, then this is a duplicate of https://github.com/fsprojects/FSharpLint/issues/336 . Closing.

Thorium commented 7 months ago

I think the problem was not .NET Framework, but rather that the project was targeting only more recent .NET than what FSharpLint uses.

knocte commented 7 months ago

Oh, oops! Reopening.

Thorium commented 7 months ago

Weirdly enough I have other projects that do work with these ones:

<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net48;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net472;net6.0</TargetFrameworks>
Numpsy commented 7 months ago

Is is related to that FunStripe project having type providers (FSharp.Data) in it?

Thorium commented 7 months ago

this has too and it works fine: https://github.com/Thorium/ClearBank.Net

Thorium commented 7 months ago

It does fail for some provided types thing:

System.Exception: 'The design-time type 'System.Boolean' utilized by a type provider was not found in the target reference assembly set '[tgt assembly FSharp.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a;
 tgt assembly System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a;
 tgt assembly FSharp.Data.Csv.Core, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.Html.Core, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.Http, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.Json.Core, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.Runtime.Utilities, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.WorldBank.Core, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259;
 tgt assembly FSharp.Data.Xml.Core, Version=6.2.0.0, Culture=neutral, PublicKeyToken=49286adf818aa259]'. You may be referencing a profile which contains fewer types than those needed by the type provider you are using.'
knocte commented 7 months ago

It does fail for some provided types thing:

That looks like a different bug, please file a new ticket (and I bet it's related to the fact that the project you're targetting is net7.0? judging by the 7.0 version of FSharp.Core mentioned in the error...)

knocte commented 7 months ago

That looks like a different bug, please file a new ticket

And don't delete your "minimal repro" msg please :)

Thorium commented 7 months ago

F# version is not related to .net version. FunStripe uses F# 7 on .NET 6. But that's the same config that the other mentioned ClearBank.NET, which does work. The minimal repo didn't replicate the issue, so there is more going on than just the sln file.

knocte commented 7 months ago

F# version is not related to .net version.

I was not referring to F# version but to FSharp.Core (nuget pkg) version, which, in the last releases of .NET match their release dates (7.0 is released when .NET7.0 is released, etc).