-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Linq.Expressions may prevent assembly unloading when using MethodInfo objects from non-collectible type with collectible generic arguments #112518
Comments
Tagging subscribers to this area: @cston |
System.Linq.Expressions has code to handle this, except that it appears to have a subtle bug as @tbdty pointed out:
|
@tbdty Would you be interested in submitting a PR with the fix that you have proposed? |
I would, but sadly I currently do not have the spare time to set up a development environment for .NET and ensure that I do everything properly. I'd greatly appreciate if someone else did this. |
I started looking into this. Are there any tests for the unloadability of assemblies? I looked and did not find any. |
The System.Linq.Expressions tests do have some coverage for collectible assemblies, but they do not explicitly verify that everything got collected. The fix discussed here was actually discussed earlier in https://github.com/dotnet/corefx/pull/25736/files#r155524477 . I would be ok with the fix without associated test. The tests to verify that everything got collected with collectible assemblies are somewhat complicated. |
When using a method from a generic class from a non-collectible assembly with a generic parameter from a collectible assembly in a LINQ expression, the collectible assembly may be prevented from unloading. This is due to the method parameters being cached in a dictionary with the method info. Fix dotnet#112518
When using a method from a generic class from a non-collectible assembly with a generic parameter from a collectible assembly in a LINQ expression, the collectible assembly may be prevented from unloading. This is due to the method parameters being cached in a dictionary with the method info. Fix #112518
Description
When you create a
MethodInfo
from a generic method in a non-collectible assembly, then callMakeGenericMethod
with a type from a collectible assembly and use the returnedMethodInfo
inSystem.Linq.Expressions.Expression.Call
the latter assembly will never be unloaded.Reproduction Steps
Create an assembly
SomeCollectibleAssembly
with a single class in it:Compile this assembly and note the path of the compiled assembly. Then create a console application with the following code:
Expected behavior
It is expected that the assembly is eventually collected by the GC and unloads, i.e. the reproduction program prints:
Actual behavior
The program never terminates and prints
repeatedly.
Regression?
No response
Known Workarounds
Using a non-generic method in a generic type works around the problem, i.e. changing the program as follows allows unloading to succeed:
Configuration
No response
Other information
I have investigated this unloading problem using WinDbg and have determined that the problem is the
TypeExtensions.s_paramInfoCache
dictionary.The problem lies in the parameter caching code: Instead of calling
method.DeclaringType?.IsCollectible
, callingmethod.IsCollectible
here should fix the problem.The text was updated successfully, but these errors were encountered: