net7.0 projects fail to parse (with exception generated at RedundantNewKeyword rule, msg `'IDisposable' required here is not available. You should add a reference to the assembly "netstandard"...`)
Description
dotnet fsharplint lint .\FsLintBug.fsproj - fails with "Failed to parse file"
Repro steps
Code to reproduce the problem:
FsLintBug.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
</ItemGroup>
</Project>
Program.fs
open LibGit2Sharp
printfn "Hello from F#"
let pathToGitRepository = "some-path"
let repo = new Repository(pathToGitRepository) // fails with "Failed to parse file"
// let repo = Repository(pathToGitRepository) // ok
Commands:
dotnet build - ok
dotnet fsharplint lint .\FsLintBug.fsproj - fails with "Failed to parse file":
Failed to parse file Program.fs
Exception Message:
The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: The type 'IDisposable' required here is not available. You should add a reference to the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".)
Exception 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.Import.ImportTypeRefData(ImportMap env, Range m, ILScopeRef scoref, String[] path, String typeName) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 106
at FSharp.Compiler.Import.ImportILTypeRefUncached(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 143
at FSharp.Compiler.Import.ImportILTypeRef(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 151
at FSharp.Compiler.Import.ImportILType(ImportMap env, Range m, FSharpList`1 tinst, ILType ty) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 180
at [email protected](ILType ity) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 127
at Microsoft.FSharp.Primitives.Basics.List.chooseToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 xs) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 178
at Microsoft.FSharp.Primitives.Basics.List.choose[T,TResult](FSharpFunc`2 f, FSharpList`1 xs) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 193
at Microsoft.FSharp.Collections.ListModule.Choose[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 155
at FSharp.Compiler.Infos.GetImmediateInterfacesOfType(SkipUnrefInterfaces skipUnref, TcGlobals g, ImportMap amap, Range m, TType ty) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 150
at FSharp.Compiler.Infos.loop@185-42[a](Boolean followInterfaces, AllowMultiIntfInstantiations allowMultiIntfInst, SkipUnrefInterfaces skipUnref, FSharpFunc`2 visitor, TcGlobals g, ImportMap amap, Range m, Int32 ndeep, TType ty, Tuple`3 state) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 239
at FSharp.Compiler.Infos.FoldHierarchyOfTypeAux[a](Boolean followInterfaces, AllowMultiIntfInstantiations allowMultiIntfInst, SkipUnrefInterfaces skipUnref, FSharpFunc`2 visitor, TcGlobals g, ImportMap amap, Range m, TType ty, a acc) in D:\workspace\_work\1\s\src\fsharp\lib.fs:line 256
at FSharp.Compiler.Infos.AllSuperTypesOfType(TcGlobals g, ImportMap amap, Range m, AllowMultiIntfInstantiations allowMultiIntfInst, TType ty) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 282
at <StartupCode$FSharp-Compiler-Service>[email protected](IEnumerable`1& next) in D:\workspace\_work\1\s\src\fsharp\symbols\Symbols.fs:line 588
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 368
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System.Collections.IEnumerator.MoveNext() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 400
at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
at FSharp.Compiler.Symbols.FSharpEntity.get_AllInterfaces() in D:\workspace\_work\1\s\src\fsharp\symbols\Symbols.fs:line 587
at FSharpLint.Rules.RedundantNewKeyword.doesNotImplementIDisposable(FSharpCheckFileResults checkFile, LongIdentWithDots ident, Unit unitVar0) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Rules\Conventions\RedundantNewKeyword.fs:line 32
at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 222
at [email protected](LintWarning suggestion) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 249
at Microsoft.FSharp.Collections.Internal.IEnumerator.choose@171.System.Collections.IEnumerator.MoveNext() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 179
at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action, IEnumerable`1 source) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 496
at FSharpLint.Application.Lint.lint(LintInfo lintInfo, FileParseInfo fileInfo) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 243
Expected behavior
No parse errors, just warning as expected
========== Linting Program.fs ==========
Usage of `new` keyword here is redundant.
Error on line * starting at column *
let repo = new Repository(options.Repo)
Actual behavior
fails with "Failed to parse file"
Known workarounds
Don't use redundant new` keyword.
let repo = new Repository(pathToGitRepository) // fails with "Failed to parse file"
// let repo = Repository(pathToGitRepository) // ok
Related information
Package Id Version Commands
dotnet-fsharplint 0.21.3 dotnet-fsharplint
Hello @makeProjectGreatAgain , thanks for your bug report. Sorry for the late reply.
Can you reproduce the same problem if you use the solution file instead of the project file?
And can you provide the project file in case the result is the same?
Hello
Can you reproduce the same problem if you use the solution file instead of the project file?
Yes, the result remains the same.
And can you provide the project file in case the result is the same?
Yes, you can see it above ( look for FsLintBug.fsproj ) A code to reproduce the problem povided in section "Repro steps". It contains only two small files FsLintBug.fsproj and Program.fs ( less than 20 lines for both ).
We discovered a workaround for now: change net7.0 to net5.0 in the project file.