FsiEvaluationSession.Create does not unload FSI-ASSEMBLY when `collectible = true`
See original GitHub issueSuccinct description
When collectible = true
is passed as an argument to FsiEvaluationSession.Create
, the FSI-ASSEMBLY is never unloaded, contrary to expectations.
Repro steps
The problem can be reproduced by following these steps:
- Run the provided collectionTest function in the Collectible code generation section of the FCS API documentation: https://fsharp.github.io/fsharp-compiler-docs/fcs/interactive.html#Collectible-code-generation
- Observe that the FSI-ASSEMBLY is never unloaded.
Expected behavior
When collectible = true
is set, the FSI-ASSEMBLY should be unloaded when it’s no longer needed.
Actual behavior
The FSI-ASSEMBLY is never unloaded, even when collectible = true
.
Known workarounds
There are currently no known workarounds for this issue.
Potential solution
A potential fix might involve modifying the defineDynamicAssemblyAndLog
function in ilreflect.fs
to ensure that the assembly is created within a CollectibleAssemblyLoadContext
. Here’s the current implementation of the function:
let defineDynamicAssemblyAndLog (asmName, flags, asmDir: string) =
let asmB = AssemblyBuilder.DefineDynamicAssembly(asmName, flags)
if logRefEmitCalls then
printfn "open System"
printfn "open System.Reflection"
printfn "open System.Reflection.Emit"
printfn
"let assemblyBuilder%d = System.AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName(Name=\"%s\"), enum %d, %A)"
(abs <| hash asmB)
asmName.Name
(LanguagePrimitives.EnumToValue flags)
asmDir
asmB
Related information
Operating system: Windows 10 Pro 21H2 (19044.3086) .NET Runtime kind: .NET 7.0.306 Editing Tools: Visual Studio Code
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
We’ll what we can do, when we wrap up our work for .NET 8 release.
@vzarytovskii Thank you for your response and your openness to accepting a PR for this issue. I appreciate the complexity of this problem, especially with the multiemit option and the potential implications for debugging.
Currently, my project is in an early development phase and my bandwidth is quite limited due to other ongoing projects. Although this issue is significant to me and may potentially become critical in the future, I’m unable to commit to contributing a PR at this moment.