@@ -1576,6 +1576,36 @@ public class PublicClass
1576
1576
"System.Diagnostics.DebuggableAttribute" } ,
1577
1577
compWithReal . SourceModule . GetReferencedAssemblySymbols ( ) . Last ( ) . GetAttributes ( ) . Select ( a => a . AttributeClass . ToTestDisplayString ( ) ) ) ;
1578
1578
1579
+ // Verify metadata (types, members, attributes) of the regular assembly with IncludePrivateMembers accidentally set to false.
1580
+ // Note this can happen because of binary clients compiled against old EmitOptions ctor which had IncludePrivateMembers=false by default.
1581
+ // In this case, IncludePrivateMembers is silently set to true when emitting
1582
+ // See https://github.com/dotnet/roslyn/issues/20873
1583
+ var emitRegularWithoutPrivateMembers = EmitOptions . Default . WithIncludePrivateMembers ( false ) ;
1584
+ CompileAndVerify ( comp , emitOptions : emitRegularWithoutPrivateMembers , verify : true ) ;
1585
+
1586
+ var realImage2 = comp . EmitToImageReference ( emitRegularWithoutPrivateMembers ) ;
1587
+ var compWithReal2 = CreateCompilation ( "" , references : new [ ] { MscorlibRef , realImage2 } ,
1588
+ options : TestOptions . DebugDll . WithMetadataImportOptions ( MetadataImportOptions . All ) ) ;
1589
+ AssertEx . Equal (
1590
+ new [ ] { "<Module>" , "<>f__AnonymousType0<<anonymous>j__TPar>" , "PublicClass" } ,
1591
+ compWithReal2 . SourceModule . GetReferencedAssemblySymbols ( ) . Last ( ) . GlobalNamespace . GetMembers ( ) . Select ( m => m . ToDisplayString ( ) ) ) ;
1592
+
1593
+ AssertEx . Equal (
1594
+ new [ ] { "void PublicClass.PublicMethod()" , "void PublicClass.PrivateMethod()" ,
1595
+ "void PublicClass.ProtectedMethod()" , "void PublicClass.InternalMethod()" ,
1596
+ "void PublicClass.PublicEvent.add" , "void PublicClass.PublicEvent.remove" ,
1597
+ "void PublicClass.InternalEvent.add" , "void PublicClass.InternalEvent.remove" ,
1598
+ "PublicClass..ctor()" ,
1599
+ "event System.Action PublicClass.PublicEvent" , "event System.Action PublicClass.InternalEvent" } ,
1600
+ compWithReal2 . GetMember < NamedTypeSymbol > ( "PublicClass" ) . GetMembers ( )
1601
+ . Select ( m => m . ToTestDisplayString ( ) ) ) ;
1602
+
1603
+ AssertEx . Equal (
1604
+ new [ ] { "System.Runtime.CompilerServices.CompilationRelaxationsAttribute" ,
1605
+ "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute" ,
1606
+ "System.Diagnostics.DebuggableAttribute" } ,
1607
+ compWithReal2 . SourceModule . GetReferencedAssemblySymbols ( ) . Last ( ) . GetAttributes ( ) . Select ( a => a . AttributeClass . ToTestDisplayString ( ) ) ) ;
1608
+
1579
1609
// verify metadata (types, members, attributes) of the metadata-only assembly
1580
1610
var emitMetadataOnly = EmitOptions . Default . WithEmitMetadataOnly ( true ) ;
1581
1611
CompileAndVerify ( comp , emitOptions : emitMetadataOnly , verify : true ) ;
@@ -1732,15 +1762,16 @@ public void IncludePrivateMembers_DisallowMetadataPeStream()
1732
1762
}
1733
1763
1734
1764
[ Fact ]
1735
- public void MustIncludePrivateMembersUnlessRefAssembly ( )
1765
+ [ WorkItem ( 20873 , "https://github.com/dotnet/roslyn/issues/20873" ) ]
1766
+ public void IncludePrivateMembersSilentlyAssumedTrueWhenEmittingRegular ( )
1736
1767
{
1737
1768
CSharpCompilation comp = CreateCompilation ( "" , references : new [ ] { MscorlibRef } ,
1738
1769
options : TestOptions . DebugDll . WithDeterministic ( true ) ) ;
1739
1770
1740
1771
using ( var output = new MemoryStream ( ) )
1741
1772
{
1742
- Assert . Throws < ArgumentException > ( ( ) => comp . Emit ( output ,
1743
- options : EmitOptions . Default . WithIncludePrivateMembers ( false ) ) ) ;
1773
+ // no exception
1774
+ _ = comp . Emit ( output , options : EmitOptions . Default . WithIncludePrivateMembers ( false ) ) ;
1744
1775
}
1745
1776
}
1746
1777
0 commit comments