Skip to content

Anonymous Record error in fsi #6411

Closed
Closed

Description

@kevmal

FSI has issues if on first use of an anonymous record an exception is thrown.

Repro steps

let a = {|A = 1|}
do failwith ""

Run the above twice in FSI. On first run an exception is thrown as exprected, on second run there's an error

C:\Users\User\AppData\Local\Temp\unknown(1,1): error FS3216: type '<>f__AnonymousType1324739542`1'' not found in assembly '<emitted>'. A possible cause may be a version incompatibility. You may need to explicitly reference the correct version of this assembly to allow all referenced components to use the correct version.

Expected behavior

Exception thrown both times.

Actual behavior

Error FS3216.

Known workarounds

Reset FSI.

Related information

Tested on VS2019 preview 4.4

Activity

  1. added this to the 16.1 milestone on Apr 1, 2019
  2. cartermp commented on Apr 1, 2019

    @cartermp
    Contributor

    @dsyme FYI

  3. modified the milestones: 16.1, 16.2 on Apr 23, 2019
  4. modified the milestones: 16.2, Backlog on Apr 30, 2019
  5. cartermp commented on Jun 18, 2019

    @cartermp
    Contributor

    Confirmed as not resolved yet for VS 16.2.

  6. Happypig375 commented on Oct 7, 2019

    @Happypig375
    Member

    Confirmed as not resolved yet for VS 16.3.2

  7. kevmal commented on Aug 26, 2020

    @kevmal
    ContributorAuthor

    More specifically IlxAssemblyGenerator is maintaining a AnonTypeGenerationTable. State becomes inconsistent when a new type is added to the anonymous type table and an error is hit in user code here:

    fsharp/src/fsharp/fsi/fsi.fs

    Lines 1154 to 1166 in ec5bad3

    timeReporter.TimeOpIf istate.timing (fun () ->
    execs |> List.iter (fun exec ->
    match exec() with
    | Some err ->
    match errorLogger with
    | :? ErrorLoggerThatStopsOnFirstError as errorLogger ->
    fprintfn fsiConsoleOutput.Error "%s" (err.ToString())
    errorLogger.SetError()
    errorLogger.AbortOnError(fsiConsoleOutput)
    | _ ->
    raise (StopProcessingExn (Some err))
    | None -> ())) ;

  8. added
    Impact-Medium
    on Aug 26, 2020
  9. self-assigned this
    on Aug 26, 2020
  10. nhirschey commented on Nov 30, 2020

    @nhirschey
    Contributor

    This bug is problematic for interactive scripting. I wanted to use anonymous records for interactive scripting. I use failwith to help build up a data file processing script, using failwith to emit information about unhandled cases. This is a great use case for anonymous records, but this bug meant that I had to restart fsi every time I found and fixed an unhandled case.

    Restarting fsi frequently is unproductive with large data files, so I had to abandon using anonymous records in my script. Another example of kevmal's problem, but more specific to my use case.

    // Failing version
    match ({| A = "test" |}.A) with
    | "tests" -> "success"
    | fail -> failwith (sprintf "expected tests but got %s" fail)
    // System.Exception: expected tests but got test
    //   at <StartupCode$FSI_0002>.$FSI_0002.main@()
    // Stopped due to error
    
    // Fixed the match statement, but now I get
    match ({| A = "tests" |}.A) with
    | "tests" -> "success"
    | fail -> failwith (sprintf "expected tests but got %s" fail)
    (* 
     error FS3216: type '<>f__AnonymousType1324739542`1' not found in assembly '<emitted>'. A possible cause may be a version incompatibility. You may need to explicitly reference the correct version of this assembly to allow all referenced components to use the 
    correct version.
    
    *)
  11. bmitc commented on Dec 11, 2020

    @bmitc
    Contributor

    I came across this today, and the error only shows up in FSI by using a script to load and open modules, as the solution and projects build without error and all tests pass.

    I took working code and simply added the [<Struct>] attribute to a bunch of record definitions to do some performance testing with no other changes. Such as:

    [<Struct>]
    type Ray = { Origin: Point; Direction: Vector}
    

    Upon doing so, I received an error, which I also didn't understand.

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

    So I removed the [<Struct>] attribute from all the record mentioned and re-ran my load script. Then I started getting the anonymous type not found error. (It is also possible the error was reported along with the above error the first time, but I can't remember.) I am only using a single anonymous record in my code, and that's inside an exception definition:

    exception InvalidDimension of {| Row: int; Column: int; Message: string |}
    

    This issue is a bit tricky to reproduce, and I am actually now (at the moment at least) unable to do so after getting rid of it. To get rid of the error I removed all [<Struct>] attributes and reset FSI interactive. There's some strange interaction with FSI in my codebase and adding [<Struct>] to a bunch of types (or certain types) and these errors.

  12. 4 remaining items

  13. abonie commented on May 4, 2023

    @abonie
    Member

    @dsyme are you still planning to look into this one?

  14. dsyme commented on May 4, 2023

    @dsyme
    Contributor

    No current plan, I'll remove the self-assignment

  15. removed their assignment
    on May 4, 2023
  16. modified the milestones: Backlog, May-2023 on May 4, 2023
  17. self-assigned this
    on May 4, 2023
  18. modified the milestones: May-2023, June-2023 on Jun 1, 2023
  19. abonie commented on Jun 22, 2023

    @abonie
    Member

    So seems like original issue got resolved somewhere around .NET 6, but the issue reported by drhumlen is still unresolved. And btw I got a smaller repro:

    > {| ab = {| a = 0; b = 0 |} |};;
    
    
    unknown(1,1): error FS0073: internal error: One of your modules expects the type '<>f__AnonymousType2475635975`2' to be defined within the module being emitted. You may be missing an input file
    
    
    
    error FS0192: internal error: Error in pass3 for type FSI_0003, error: Processing of a script fragment has stopped because an exception has been raised
    

    Names of the labels are part of the issue, because this works ok:

    > {| ab = {| a = 0; c = 0 |} |};;
    val it: {| ab: {| a: int; c: int |} |} = { ab = { a = 0
                                                      c = 0 } }
  20. modified the milestones: June-2023, July-2023 on Jul 6, 2023
  21. abonie commented on Jul 13, 2023

    @abonie
    Member

    The secondary issue mentioned above should be fixed by #15519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-FSIBugImpact-Medium

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions