-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
NullabilityInfoContext.Create throws IndexOutOfRangeException #68461
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsDescription
Reproduction Steps
Expected behaviorProgram should successfully terminate with Nullable displayed on the console. Actual behaviorLine
Regression?No response Known WorkaroundsNo response ConfigurationThis is a vanilla .NET 6.0 Long-term Support "Console App" project created in Visual Studio 2022 on a Windows 11 machine. Fails in both Debug and Release mode when targeting "Any CPU".
Other informationNo response
|
Here are some more cases that will fail, this time without referencing lists or dictionaries.
|
Thanks for the report @ropufu . Any interest in debugging a bit, or offering a fix? |
I'll give it a shot :^) However, I'm very new to creating PR and almost hopeless at git. So this will take me a while to read through all relevant instructions. |
Sure - take your time and let me know if you get stuck. There are pretty good workflow instructions though. |
Nice report, @ropufu. I can reproduce it with net7.0 as well. A quick fix is to change this line: runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs Line 462 in a9f9745
as for (int i = 0; i < genericArguments.Length && i < nullability.GenericTypeArguments.Length; i++) . However, I think it is not the right fix as nullability.GenericTypeArguments should account for same number of generic arguments as metadata.GetGenericArguments() so the checks will run for each nested argument as well, right?
using System.Reflection;
Foo<int> bar = new();
NullabilityInfoContext context = new();
PropertyInfo x0 = bar.GetType().GetProperty(nameof(bar.Prop0))!;
NullabilityInfo info0 = context.Create(x0); // fine
PropertyInfo x1 = bar.GetType().GetProperty(nameof(bar.Prop1))!;
NullabilityInfo info1 = context.Create(x1); // throws IOoRE
class Foo<T>
{
public Two<int, T> Prop0 { get; set; }
public Two<int, One<T>> Prop1 { get; set; }
}
class Two<T, U> { }
class One<T> { } @madelson, do you remember seeing this case while working on #64143? |
@am11 I don't recall running into this. I'm surprised that the test cases don't cover this given that the repro seems fairly simple.
Agreed. We need to figure out why these differ. I'd be happy to take this if @ropufu doesn't end up wanting to. |
Hello @ropufu? Are you still working on it? It better to be fixed within 7.0 preview 7 and not many days left |
Thank you for the nudge. I wasn't for a while: I could not follow the Contributing/Workflow guidelines to set up debugging for the issue in conjunction with System.Private.CoreLib back then... and I still can't. If there is a deadline for me to aim at--that would be helpful (assuming that leaves you folks enough time to crack it if I fail). And if you have other references (like a minimal example/walkthrough how to set up a debuggable project in VS that targets the preview .NET) that would be most welcome. My apologies for not speaking up the first time I could not do it. |
After building
The preview 7 deadline is next Monday, so if you could do the fix within this week |
@buyaa-n Thank you so much for your help. Right to the point. Saved me a lot of frustration and pain. Thank you! I think I managed to get the thing fixed. Reflection tests look good; I'll try to get the proper submission done in an hour or two. My only concern is that I am not so fluent in the |
The TryLoadGenericMetaTypeNullability method was called with the same member info but varying nullability across the entire nullability hierarchy. Moved it one level up where nullability and member info are aligned. Added a test to cover this issue. Fix dotnet#68461
Description
NullabilityInfoContext
will throwIndexOutOfRangeException
when callingCreate
method on certainDictionary
-valued properties in generic classes. Seems to happen when theTValue
of the dictionary is a generic class with one type parameter coinciding with the type parameter of the class that defines the property.Reproduction Steps
Expected behavior
Program should successfully terminate with Nullable displayed on the console.
Actual behavior
Line
NullabilityInfo info = context.Create(x);
throws aSystem.IndexOutOfRangeException
.Regression?
No response
Known Workarounds
No response
Configuration
This is a vanilla .NET 6.0 Long-term Support "Console App" project created in Visual Studio 2022 on a Windows 11 machine. Fails in both Debug and Release mode when targeting "Any CPU".
Other information
No response
The text was updated successfully, but these errors were encountered: