You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FSI has issues if on first use of an anonymous record an exception is thrown.
Repro steps
leta={|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.
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:
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 versionmatch({| 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 getmatch({| 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.*)
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:
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.
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|}|};;valit:{| ab:{| a: int; c: int |}|}={ ab ={ a = 0
c = 0 }}
Activity
cartermp commentedon Apr 1, 2019
@dsyme FYI
cartermp commentedon Jun 18, 2019
Confirmed as not resolved yet for VS 16.2.
Happypig375 commentedon Oct 7, 2019
Confirmed as not resolved yet for VS 16.3.2
kevmal commentedon Aug 26, 2020
More specifically
IlxAssemblyGeneratoris maintaining aAnonTypeGenerationTable. 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
nhirschey commentedon Nov 30, 2020
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.
bmitc commentedon Dec 11, 2020
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:Upon doing so, I received an error, which I also didn't understand.
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: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.4 remaining items
abonie commentedon May 4, 2023
@dsyme are you still planning to look into this one?
dsyme commentedon May 4, 2023
No current plan, I'll remove the self-assignment
abonie commentedon Jun 22, 2023
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:
Names of the labels are part of the issue, because this works ok:
abonie commentedon Jul 13, 2023
The secondary issue mentioned above should be fixed by #15519