dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 784 forks source link

Expr.TryGetReflectedDefinition on Blazor WebAssembly #14054

Open krauthaufen opened 1 year ago

krauthaufen commented 1 year ago

In our Blazor WebAssembly project Expr.TryGetReflectedDefinition fails when I change definetly unrelated parts of the code. Basically we use quotations for our shaders in FShade and by changing an entirely different part of the code we suddenly see

this error message update failed: System.InvalidOperationException: type argument out of range blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.mkTyparSubst@2006.Invoke(Int32 idx) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2010 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_dtype@1969.Invoke(FSharpFunc`2 env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1969 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.appL@1963[[Microsoft.FSharp.Core.FSharpFunc`2[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(FSharpFunc`2 f) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1963 blazor.webassembly.js:1 at Microsoft.FSharp.Primitives.Basics.List.map[FSharpFunc`2,Type](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 245 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.appL[FSharpFunc`2,Type](FSharpList`1 fs, FSharpFunc`2 env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1963 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_dtype@1970-3.Invoke(FSharpFunc`2 env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1970 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.appL@1963[[Microsoft.FSharp.Core.FSharpFunc`2[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(FSharpFunc`2 f) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1963 blazor.webassembly.js:1 at Microsoft.FSharp.Primitives.Basics.List.map[FSharpFunc`2,Type](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 243 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.appL[FSharpFunc`2,Type](FSharpList`1 fs, FSharpFunc`2 env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1963 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_dtype@1970-3.Invoke(FSharpFunc`2 env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 1970 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_VarDecl@2070.Invoke(BindingEnv env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2070 2blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@2048-2.Invoke(BindingEnv env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2048 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@2059-5.Invoke(BindingEnv env) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2059 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.tryGetReflectedDefinition(MethodBase methodBase, Type[] tyargs) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2542 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.PatternsModule.tryGetReflectedDefinitionInstantiated(MethodBase methodBase) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2558 blazor.webassembly.js:1 at Microsoft.FSharp.Quotations.FSharpExpr.TryGetReflectedDefinition(MethodBase methodBase) in D:\a\_work\1\s\src\FSharp.Core\quotations.fs:line 2765

Repro steps

The whole project is sadly proprietary and all attempts to repoduce it in a smaller project failed so far.

I'm hoping someone can guess what this is without a repro but I'm still trying to find a minimal setup.

Edit: all trimming and AOT are disabled btw.

Expected behavior

Doesn't crash

Actual behavior

crashes in Expr.TryGetReflectedDefinition

Known workarounds

sadly none.

Related information

running on Blazor.WebAssembly with:

krauthaufen commented 1 year ago

I found a clue: Expr.TryGetReflectedDefinition fails on F#-style extension properties that are defined in a referenced library and shouldn't have any reflected definitions. Still the relevant parts have not been changed since before the error happened.

T-Gro commented 1 year ago

I found a clue: Expr.TryGetReflectedDefinition fails on F#-style extension properties that are defined in a referenced library and shouldn't have any reflected definitions. Still the relevant parts have not been changed since before the error happened.

Hi @krauthaufen . Does this exhibit itself also in a non-Blazor situation? Would be great to have a minimal sample

krauthaufen commented 1 year ago

Not yet, I'm still looking for a repro but it doesn't seem to happen in the "real" dotnet. My guess would be some wrong name-mangling in the old mono code since these extensions get weird names containing a . in the methodname afaik. Maybe somr reflection stuff going wrong with these names...

T-Gro commented 1 year ago

Would it be possible to send anything share-able? We could discuss it with local WebAssembly folks.

krauthaufen commented 1 year ago

I still couldn't reproduce that deterministically, it randomly happens after some changes and disappears once I add some more code for example. I can freeze our project the next time it happens and share the code with you personally