-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Accessing an unitialized array throws a NullReferenceException but at the wrong line #42994
Comments
Is this a debug or release build? |
I can repro this (16.6p2, Debug configuration for the project). The highlight for the breakpoint currently shows |
Tagging @cshung I verified that the sequence points are produced as I expect (see repro below). [Fact, WorkItem(42994, "https://github.com/dotnet/roslyn/issues/42994")]
public void Repro()
{
string source = @"
class C
{
static string[] SomeArray = null;
static void M()
{
SomeArray[1] = string. Empty;
DoSomething();
}
static void DoSomething() { }
}
";
var compilation = CompileAndVerify(source);
compilation.VerifyIL("C.M",
@"
{
// Code size 18 (0x12)
.maxstack 3
// sequence point: SomeArray[1] = string. Empty;
IL_0000: ldsfld ""string[] C.SomeArray""
IL_0005: ldc.i4.1
IL_0006: ldsfld ""string string.Empty""
IL_000b: stelem.ref
// sequence point: DoSomething();
IL_000c: call ""void C.DoSomething()""
// sequence point: }
IL_0011: ret
}
", sequencePoints: "C.M", source: source);
} |
@dotnet/dotnet-diag |
@mikem8361 seems similar to dotnet/runtime#34226 |
Yes, it is. This issue could be linked to that one and closed.
|
Thanks. Closing as duplicate of dotnet/runtime#34226 |
This issue has been moved from a ticket on Developer Community.
Consider the following code to reproduce:
Obviously,
SomeArray
is never initialized and trying to access it (at line #15) would throw a NullReferenceException. However, the debugger shows the exception at the next line (line #16) and the stack trace is as follows:> ConsoleApp1.exe! ConsoleApp1.Program.Main(string[] args) Line 16 C#
I was able to reproduce this on both VS2017 and VS2019.
Original Comments
Visual Studio Feedback System on 3/31/2020, 00:55 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
The text was updated successfully, but these errors were encountered: