fsprojects / FSharpLint

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

Original message: The type 'IServer' is required here and is unavailable. #575

Open abelbraaksma opened 1 year ago

abelbraaksma commented 1 year ago

Description

When checking for redunant 'new' keyword, FSharpLint can throw when dependencies aren't readily available. I'm not quite sure how to make a minimal repro, but it basically seems that FSL doesn't get all dependencies properly.

Normal compile is fine, as is running, so all dependencies are resolves properly by F#.

Repro steps

Not sure, this is a rather large project, but I'll try to make a smallish repro, unless the reflection-walk in the offending code has a clear location where this goes haywire.

Expected behavior

No error

Actual behavior

Getting this error:

Failed to parse file d:\Projects\Test\MyManagement.Tests\Host\WebHostTestServer.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 'IServer' is required here and is unavailable. You must add a reference to assembly 'Microsoft.AspNetCore.Hosting.Server.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.)
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 118
   at FSharp.Compiler.Import.ImportILTypeRefUncached(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 141
   at FSharp.Compiler.Import.ImportILTypeRef(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 153
   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 FSharp.Compiler.Infos.getInterfaces@125-3.Invoke(ILType ity) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 127
   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 189
   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 174
   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 252
   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>.$Symbols.get_AllInterfaces@588.GenerateNext(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.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 FSharpLint.Application.Lint.typeCheckSuggestion@249.Invoke(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

Known workarounds

None

Related information

Latest FSharpLint, F# 6.0, .NET 6.0, Windows

abelbraaksma commented 1 year ago

Actually, that wasn't entirely correct. A working workaround is to add the redundant, transient dependency by hand. Do note, though, that the reported version number in the error is wrong, but at least the error is gone now.

knocte commented 1 year ago

Hey Abel, thanks for filing this bug and providing a workaround.

Do note, though, that the reported version number in the error is wrong

You mean the version contained in the text "Microsoft.AspNetCore.Hosting.Server.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"? Unfortunately, the culprit with that issue might just be that the version listed in the nuget package is not the same as the ASSEMBLY version. This happens quite often in many libraries :(

abelbraaksma commented 1 year ago

@knocte ah, yes, that makes sense (re version weirdness)

knocte commented 6 months ago

@abelbraaksma hello Abel, we have a new prerelease that is completely transitioned to .net6.0 and I have the feeling that it might have some impact on this bug. Do you mind upgrading to it and re-testing?

knocte commented 6 months ago

(The latest pre-release: https://www.nuget.org/packages/dotnet-fsharplint/0.23.1--date20231228-0934.git-e8d2697 )

abelbraaksma commented 6 months ago

I'll give it a go, I'd love to use it again! Great work!