Skip to content

Fsi error with nested struct record  #10060

Closed

Description

@kevmal
[<Struct>]
type RecordA = { Value : double }

[<Struct>]
type RecordB = { A : RecordA }

{ A = { Value = 0.0 } }

In fsi produces the error:

error FS0193: internal error: Could not load type 'FSI_0004' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

Tested both

  • F# Interactive version 11.0.0.0 for F# 5.0
  • F# Interactive version 10.9.1.0 for F# 4.7

Some other notes:

  • With fsc, the fsx file compiles and runs fine
  • If either record is not a struct it runs fine
  • It can be run in pieces. Definitions first, then record ctor and it runs fine.

Activity

  1. dsyme commented on Sep 3, 2020

    @dsyme
    Contributor

    I think this is the long standing issue where code submissions that contain both struct definitions and building top-vel statically initialized values for those structs can, in some situations, lead to problems with type loading in .NET

    It's the smallest repro of the issue I've seen however, so it's very useful

    I'll dig out the canonical issue for this and add this repro

  2. added
    Impact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
    on Sep 4, 2020
  3. dsyme commented on Sep 4, 2020

    @dsyme
    Contributor

    Tecnnically I believe the problem here is that these struct types are nested types - nested in the module. When one is loaded, it tries to load the other, which forces the load of the containing type, which is not yet completed for some reason due to the first load or the evaluation of the static field or something.

    This is AFAIK a .NET reflection emit type loading limitation

    Placing the struct types or values in a separate namespace of module is a workaround, e.g.

    [<Struct>]
    type RecordA = { Value : double }
    
    [<Struct>]
    type RecordB = { A : RecordA }
    
    module Values = 
        let v = { A = { Value = 0.0 } }
    
  4. dsyme commented on Mar 4, 2022

    @dsyme
    Contributor

    This is fixed by multi-assembly emit which is now used by default #12722

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

    Area-FSIBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions