FileLoadException using .NET 7 and a web api
Hey Joe, I have a script that runs a web api that works fine in .NET 6.0 and below but when I run it in .NET 7.0 I get a FileLoadException and LINQPad breaks at services.AddControllers
. The InnerException is a NotSupportedException
with the message "A non-collectible assembly may not reference a collectible assembly."
After digging around for a while I found an older thread where you mentioned that the error would be accompanied by the following message: "Tip: You can make the query's load-context non-collectible by checking the option in Query Properties | Advanced (press F4)". However, I don't see this in .NET 7.0 so it took a bit to figure it out. The checkbox in the advanced query properties does indeed fix the issue for me but I wanted to let you know that the helpful error message doesn't show up in this scenario.
I wonder if the following breaking change is what caused the message not to show up in LINQPad any longer:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/7.0/collectible-assemblies
Since this is an option that we need to turn on I'm also curious what we lose by using it? In other words, what harm would it cause to use it by default or by having something in the LINQPad preferences to do this by default?
Comments
Can you provide a repro?
Non-collectible assemblies eat up memory that cannot be reclaimed. So every time you edit your query and re-run, a small amount of memory leaks via the old assembly. This is usually small enough to go unnoticed unless it's a very large query and you've made a lot of edits without killing the process (e.g., with a Cancel).
Sure, here you go.
http://share.linqpad.net/k8337w.linq
I can't reproduce this. Can you provide a screenshot (also along with the exception details)?
Here's what I see:
That's embarrassing. It seems I have become conditioned to totally gloss over the yellow message there and go straight to the Results when something goes wrong. I expected to see the message there.
Sorry for the false alarm!
No worries, thanks for the heads-up.