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

Ignore bit flag AssemblyFlags.PublicKey for assembly definitions

上级 fa8065f2
......@@ -1650,8 +1650,8 @@ internal void Foo()
}
}
[Fact(Skip = "Bug 399")]
[WorkItem(399, "GitHub")]
[Fact]
[WorkItem(399, "https://github.com/dotnet/roslyn/issues/399")]
public void Bug399()
{
// The referenced assembly Signed.dll from the repro steps
......
......@@ -474,14 +474,18 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow()
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))
{
throw new BadImageFormatException(string.Format(CodeAnalysisResources.InvalidCultureName, cultureName));
}
var hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0;
var publicKeyOrToken = !publicKey.IsNil ? reader.GetBlobBytes(publicKey).AsImmutableOrNull() : default(ImmutableArray<byte>);
ImmutableArray<byte> publicKeyOrToken = reader.GetBlobContent(publicKey);
bool hasPublicKey;
if (isReference)
{
hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0;
if (hasPublicKey)
{
if (!MetadataHelpers.IsValidPublicKey(publicKeyOrToken))
......@@ -489,17 +493,30 @@ internal AssemblyIdentity ReadAssemblyIdentityOrThrow()
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);
}
}
}
else
{
// Assembly definitions do not contain public key tokens, but they may contain public key
// data without being marked as strong name signed (e.g. delay-signed assemblies).
// Assembly definitions never contain a public key token, they only can have a full key or nothing,
// 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>);
}
......
......@@ -1050,8 +1050,8 @@ static void M()
context.CompileExpression(
// 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").
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("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("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=1f8a32457d187bf3]], 397300B0-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"),
"(object)$exception ?? (object)$1 ?? $2",
DkmEvaluationFlags.TreatAsExpression,
DiagnosticFormatter.Instance,
......
......@@ -859,8 +859,8 @@ End Class"
' GetType(Exception), GetType(A(Of B(Of Object))), GetType(B(Of A(Of Object)()))
context.CompileExpression(
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("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("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=1f8a32457d187bf3]], 397300B1-B, Version=1.2.2.2, Culture=neutral, PublicKeyToken=null"),
"If(If($exception, $1), $2)",
DkmEvaluationFlags.TreatAsExpression,
DiagnosticFormatter.Instance,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册