提交 b291cb05 编写于 作者: V Vladimir Reshetnikov

Ignore bit flag AssemblyFlags.PublicKey for assembly definitions

上级 fa8065f2
...@@ -1650,8 +1650,8 @@ internal void Foo() ...@@ -1650,8 +1650,8 @@ internal void Foo()
} }
} }
[Fact(Skip = "Bug 399")] [Fact]
[WorkItem(399, "GitHub")] [WorkItem(399, "https://github.com/dotnet/roslyn/issues/399")]
public void Bug399() public void Bug399()
{ {
// The referenced assembly Signed.dll from the repro steps // The referenced assembly Signed.dll from the repro steps
......
...@@ -474,14 +474,18 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow() ...@@ -474,14 +474,18 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow()
throw new BadImageFormatException(string.Format(CodeAnalysisResources.InvalidAssemblyName, nameStr)); throw new BadImageFormatException(string.Format(CodeAnalysisResources.InvalidAssemblyName, nameStr));
} }
string cultureName = (!culture.IsNil) ? reader.GetString(culture) : null; string cultureName = culture.IsNil ? null : reader.GetString(culture);
if (cultureName != null && !MetadataHelpers.IsValidMetadataIdentifier(cultureName)) if (cultureName != null && !MetadataHelpers.IsValidMetadataIdentifier(cultureName))
{ {
throw new BadImageFormatException(string.Format(CodeAnalysisResources.InvalidCultureName, cultureName)); throw new BadImageFormatException(string.Format(CodeAnalysisResources.InvalidCultureName, cultureName));
} }
var hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0; ImmutableArray<byte> publicKeyOrToken = reader.GetBlobContent(publicKey);
var publicKeyOrToken = !publicKey.IsNil ? reader.GetBlobBytes(publicKey).AsImmutableOrNull() : default(ImmutableArray<byte>); bool hasPublicKey;
if (isReference)
{
hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0;
if (hasPublicKey) if (hasPublicKey)
{ {
if (!MetadataHelpers.IsValidPublicKey(publicKeyOrToken)) if (!MetadataHelpers.IsValidPublicKey(publicKeyOrToken))
...@@ -489,17 +493,30 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow() ...@@ -489,17 +493,30 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow()
throw new BadImageFormatException(CodeAnalysisResources.InvalidPublicKey); throw new BadImageFormatException(CodeAnalysisResources.InvalidPublicKey);
} }
} }
else if (isReference) else
{ {
if (!publicKeyOrToken.IsDefaultOrEmpty && publicKeyOrToken.Length != AssemblyIdentity.PublicKeyTokenSize) if (!publicKeyOrToken.IsEmpty &&
publicKeyOrToken.Length != AssemblyIdentity.PublicKeyTokenSize)
{ {
throw new BadImageFormatException(CodeAnalysisResources.InvalidPublicKeyToken); throw new BadImageFormatException(CodeAnalysisResources.InvalidPublicKeyToken);
} }
} }
}
else else
{ {
// Assembly definitions do not contain public key tokens, but they may contain public key // Assembly definitions never contain a public key token, they only can have a full key or nothing,
// data without being marked as strong name signed (e.g. delay-signed assemblies). // so the flag AssemblyFlags.PublicKey does not make sense for them and is ignored.
// See Ecma-335, Partition II Metadata, 22.2 "Assembly : 0x20".
// This also corresponds to the behavior of the native C# compiler and sn.exe tool.
hasPublicKey = !publicKeyOrToken.IsEmpty;
if (hasPublicKey && !MetadataHelpers.IsValidPublicKey(publicKeyOrToken))
{
throw new BadImageFormatException(CodeAnalysisResources.InvalidPublicKey);
}
}
if (publicKeyOrToken.IsEmpty)
{
publicKeyOrToken = default(ImmutableArray<byte>); publicKeyOrToken = default(ImmutableArray<byte>);
} }
......
...@@ -1050,8 +1050,8 @@ static void M() ...@@ -1050,8 +1050,8 @@ static void M()
context.CompileExpression( context.CompileExpression(
// typeof(Exception), typeof(A<B<object>>), typeof(B<A<object>[]>) // typeof(Exception), typeof(A<B<object>>), typeof(B<A<object>[]>)
InspectionContextFactory.Empty.Add("$exception", "System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"). InspectionContextFactory.Empty.Add("$exception", "System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").
Add("1", "A`1[[B`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], 397300B0-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null]], 397300B0-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=null"). Add("1", "A`1[[B`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], 397300B0-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null]], 397300B0-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=1f8a32457d187bf3").
Add("2", "B`1[[A`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], 397300B0-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=null]], 397300B0-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"), Add("2", "B`1[[A`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], 397300B0-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=1f8a32457d187bf3]], 397300B0-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"),
"(object)$exception ?? (object)$1 ?? $2", "(object)$exception ?? (object)$1 ?? $2",
DkmEvaluationFlags.TreatAsExpression, DkmEvaluationFlags.TreatAsExpression,
DiagnosticFormatter.Instance, DiagnosticFormatter.Instance,
......
...@@ -859,8 +859,8 @@ End Class" ...@@ -859,8 +859,8 @@ End Class"
' GetType(Exception), GetType(A(Of B(Of Object))), GetType(B(Of A(Of Object)())) ' GetType(Exception), GetType(A(Of B(Of Object))), GetType(B(Of A(Of Object)()))
context.CompileExpression( context.CompileExpression(
InspectionContextFactory.Empty.Add("$exception", "System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"). InspectionContextFactory.Empty.Add("$exception", "System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").
Add("1", "A`1[[B`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], 397300B1-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null]], 397300B1-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=null"). Add("1", "A`1[[B`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], 397300B1-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null]], 397300B1-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=1f8a32457d187bf3").
Add("2", "B`1[[A`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], 397300B1-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=null]], 397300B1-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"), Add("2", "B`1[[A`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], 397300B1-A, Version=2.1.2.1, Culture=neutral, PublicKeyToken=1f8a32457d187bf3]], 397300B1-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"),
"If(If($exception, $1), $2)", "If(If($exception, $1), $2)",
DkmEvaluationFlags.TreatAsExpression, DkmEvaluationFlags.TreatAsExpression,
DiagnosticFormatter.Instance, DiagnosticFormatter.Instance,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册