Open WindingWinter opened 3 weeks ago
Instead of creating a minimal example, you could create a complog and send it to us for investigation. Note that it will contain all inputs, but you can send it privately via VS feedback (just link the ticket here then).
@jjonescz . here's the VS feedback link
[WorkItem("https://github.com/dotnet/roslyn/issues/74872")]
[Fact]
public void ExternAliases6()
{
string sourceA =
@"
namespace N
{
public class A { }
}
";
var comp = CreateCompilation(sourceA, assemblyName: "A1");
var refA = comp.EmitToImageReference(aliases: ImmutableArray.Create("A2"));
string sourceB =
@"
class B
{
static void F(A x) { }
}
";
string sourceC =
@"
extern alias A2;
global using A2::N;
";
comp = CreateCompilation([sourceB, sourceC], references: new[] { refA }, options: TestOptions.DebugDll);
comp.VerifyDiagnostics();
comp.VerifyPdb(
@"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""B"" name=""F"" parameterNames=""x"">
<customDebugInfo>
<using>
<namespace usingCount=""1"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""4"" startColumn=""24"" endLine=""4"" endColumn=""25"" document=""1"" />
<entry offset=""0x1"" startLine=""4"" startColumn=""26"" endLine=""4"" endColumn=""27"" document=""1"" />
</sequencePoints>
<scope startOffset=""0x0"" endOffset=""0x2"">
<namespace qualifier=""A2"" name=""N"" />
<externinfo alias=""A2"" assembly=""A1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"" />
</scope>
</method>
</methods>
</symbols>
");
}
[WorkItem("https://github.com/dotnet/roslyn/issues/74872")]
[Fact]
public void ExternAliases7()
{
string sourceA =
@"
namespace N
{
public class A { }
}
";
var comp = CreateCompilation(sourceA, assemblyName: "A1");
var refA = comp.EmitToImageReference(aliases: ImmutableArray.Create("A2"));
string sourceB =
@"
class B
{
static void F(N2.A x) { }
}
";
string sourceC =
@"
extern alias A2;
global using N2 = A2::N;
";
comp = CreateCompilation([sourceB, sourceC], references: new[] { refA }, options: TestOptions.DebugDll);
comp.VerifyDiagnostics();
comp.VerifyPdb(
@"
<symbols>
<files>
<file id=""1"" name="""" language=""C#"" />
</files>
<methods>
<method containingType=""B"" name=""F"" parameterNames=""x"">
<customDebugInfo>
<using>
<namespace usingCount=""1"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""4"" startColumn=""27"" endLine=""4"" endColumn=""28"" document=""1"" />
<entry offset=""0x1"" startLine=""4"" startColumn=""29"" endLine=""4"" endColumn=""30"" document=""1"" />
</sequencePoints>
<scope startOffset=""0x0"" endOffset=""0x2"">
<alias name=""N2"" qualifier=""A2"" target=""N"" kind=""namespace"" />
<externinfo alias=""A2"" assembly=""A1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"" />
</scope>
</method>
</methods>
</symbols>
");
}
@tmat Could you please advise what import information should be emitted for the scenarios above? Note that PdbValidation.VerifyPdb
helper doesn't like references to undefined aliases: "PDB0007: token 0x35000002: An extern alias was not defined for assembly reference 23000002". At the same time it feels like defining an alias used by a global using
would be incorrect because it is not in "scope" within sourceB
.
Interesting corner case. I need to dig deeper into the code that reports the error.
This happens with VS 2022 ( 17.11.1 version).
I have a solution, that will throw me Null Reference Exception because I'm using Global Usings. Here's the stack trace:
The workaround that I can have is that I stop using global usings. Eg: I remove the GlobalUsings.cs file that contains the following two lines of code
And the problem goes away.
But the problem is that when I try to create a scale down project, I can't reproduce the error. I thought it's a simple case of using extern alias with global using, but I was wrong.
I am pretty sure that this is a bug from Rosyln compiler. Any idea how to reproduce an actionable bug report?