Skip to content

Random crashes  #160

Description

@tmoers

Every once in a while we have two tests that fail and we get this call stack in the exception:

System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.FSharp.Quotations.FSharpVar..ctor(String name, Type typ, FSharpOption`1 isMutable) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 91
at Microsoft.FSharp.Quotations.PatternsModule.u_VarDecl@1530.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1530
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1508-2.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1508
at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 241
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 251
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1492.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1493
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 Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1492.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1493
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 Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1492.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1493
at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1519-5.Invoke(BindingEnv env) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1519
at Microsoft.FSharp.Quotations.PatternsModule.deserialize(Type localAssembly, Type[] referencedTypeDefs, Type[] spliceTypes, FSharpExpr[] spliceExprs, Byte[] bytes) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 1896
at Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40(Type qualifyingType, Type[] referencedTypes, Type[] spliceTypes, FSharpExpr[] spliceExprs, Byte[] bytes) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\quotations.fs:line 2092
at Tomra.Ts.Core.MapTests.Keys works as expected()

This is the test:

    let [<Fact>] ``Keys works as expected``() =
        let map = Map.ofList [ (1, "One"); (2, "Two"); (3, "Three") ]
        test <@ map |> Map.keys |> List.ofSeq = [1; 2; 3] @>

And this is the code being tested:

namespace global

open System

[<RequireQualifiedAccess>]
module Map =

    let keys (map: Map<_, _>) =
        seq {
            for KeyValue(key, _) in map do
                yield key
        }

I have no clue why it sometimes fails. It's all pure, nothing changes. I'm not saying it's Unquote that's at fault here, but I'm wondering if this rings a bell or if I'm maybe doing something incorrect here?

Activity

  1. stephen-swensen commented on Jan 7, 2022

    @stephen-swensen
    Contributor

    Hi @tmoers - curious, your test as written looks perfectly legitimate and I can't see offhand why it would randomly fail. The stack trace seems to indicate the issue may be within the FSharp.Core quotation code itself. Perhaps some kind of assembly loading race condition (just a hunch). I wonder if the issue could be reproduce by running the code in a loop or something like that (again just thinking aloud). I'll reflect on it a bit and maybe try some things to see if I can reproduce.

  2. added
    upstreamSource of issue is possibly upstream to Unquote (e.g. FSharp.Core)
    on Dec 31, 2023
  3. stephen-swensen commented on Nov 29, 2024

    @stephen-swensen
    Contributor

    Closing this issue as it is old and hasn't come up again and appeared to be upstream at the time.

  4. bartelink commented on Sep 10, 2026

    @bartelink
    Contributor

    Still happening with SDK 10.0.302 in CI (Release build, running on TeamCity windows agent)
    (innocuous comparing Guid.Parse output to Guid.TryParse invoked via a partial FSharpFunc with literals i.e. the test did not fail)
    same stacktrace though line numbers have shifted

  5. bartelink commented on Oct 9, 2026

    @bartelink
    Contributor

    Full stack trace from 10.0.303 on my desktop

      System.NullReferenceException : Object reference not set to an instance of an object.
      from <Path>\tests\bin\Debug\net10.0\<Project>.Tests.dll (net10.0|x64)
      Xunit.MicrosoftTestingPlatform.XunitException: System.NullReferenceException : Object reference not set to an instance of an object.
        at Microsoft.FSharp.Quotations.FSharpVar..ctor(String name, Type typ, FSharpOption`1 isMutable) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:109
        at Microsoft.FSharp.Quotations.PatternsModule.u_VarDecl@2003.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:2003
        at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1981-2.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:1981
        at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:247
        at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1963.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:1964
        at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:238
        at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:248
        at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1963.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:1964
        at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:238
        at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:248
        at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1963.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:1964
        at Microsoft.FSharp.Quotations.PatternsModule.u_Expr@1992-5.Invoke(BindingEnv env) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:1992
        at Microsoft.FSharp.Quotations.PatternsModule.deserialize(Type localAssembly, Type[] referencedTypeDefs, Type[] spliceTypes, FSharpExpr[] spliceExprs, Byte[] bytes) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:2488
        at Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40(Type qualifyingType, Type[] referencedTypes, Type[] spliceTypes, FSharpExpr[] spliceExprs, Byte[] bytes) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\quotations.fs:2699
        at Tomra.Xcd.Nucleus.MachineStatus.Health.Monitoring.Monitoring.EjectionHealthStatusTests.Ejection statistics with more than 10 percent refused lines are considered as Error() in Nucleus\src\Nucleus.MachineStatus\Health\tests\Monitoring\EjectionHealthStatusTests.fs:48
        at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
    
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

    upstreamSource of issue is possibly upstream to Unquote (e.g. FSharp.Core)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions