提交 f78d8de7 编写于 作者: A Andrew Casey

Add explicit null checks during module lookup

We got a release-build dump with a NRE in a location that didn't make sense.  Based on our best guess of what happened (something that should be impossible) add some explicit checks so that we'll get a clearer stack trace if it happens again.

No tests since we still believe this is impossible.
上级 939cefea
......@@ -21,6 +21,7 @@ private static PENamedTypeSymbol GetType(PEModuleSymbol module, TypeDefinitionHa
internal static PENamedTypeSymbol GetType(this CSharpCompilation compilation, Guid moduleVersionId, int typeToken, out MetadataDecoder metadataDecoder)
{
var module = compilation.GetModule(moduleVersionId);
CheckModule(module, moduleVersionId);
var reader = module.Module.MetadataReader;
var typeHandle = (TypeDefinitionHandle)MetadataTokens.Handle(typeToken);
var type = GetType(module, typeHandle);
......@@ -62,6 +63,7 @@ internal static PEMethodSymbol GetSourceMethod(this CSharpCompilation compilatio
internal static PEMethodSymbol GetMethod(this CSharpCompilation compilation, Guid moduleVersionId, MethodDefinitionHandle methodHandle)
{
var module = compilation.GetModule(moduleVersionId);
CheckModule(module, moduleVersionId);
var reader = module.Module.MetadataReader;
var typeHandle = reader.GetMethodDefinition(methodHandle).GetDeclaringType();
var type = GetType(module, typeHandle);
......@@ -88,6 +90,14 @@ internal static PEModuleSymbol GetModule(this CSharpCompilation compilation, Gui
return null;
}
private static void CheckModule(PEModuleSymbol module, Guid moduleVersionId)
{
if ((object)module == null)
{
throw new ArgumentException($"No module found with MVID '{moduleVersionId}'", nameof(moduleVersionId));
}
}
internal static CSharpCompilation ToCompilation(this ImmutableArray<MetadataBlock> metadataBlocks)
{
return CSharpCompilation.Create(
......
......@@ -20,6 +20,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
<Extension>
Friend Function [GetType](compilation As VisualBasicCompilation, moduleVersionId As Guid, typeToken As Integer, <Out> ByRef metadataDecoder As MetadataDecoder) As PENamedTypeSymbol
Dim [module] = compilation.GetModule(moduleVersionId)
CheckModule([module], moduleVersionId)
Dim reader = [module].Module.MetadataReader
Dim typeHandle = CType(MetadataTokens.Handle(typeToken), TypeDefinitionHandle)
Dim type = [GetType]([module], typeHandle)
......@@ -57,6 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
<Extension>
Friend Function GetMethod(compilation As VisualBasicCompilation, moduleVersionId As Guid, methodHandle As MethodDefinitionHandle) As PEMethodSymbol
Dim [module] = compilation.GetModule(moduleVersionId)
CheckModule([module], moduleVersionId)
Dim reader = [module].Module.MetadataReader
Dim typeHandle = reader.GetMethodDefinition(methodHandle).GetDeclaringType()
Dim type = [GetType]([module], typeHandle)
......@@ -80,6 +82,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Return Nothing
End Function
Private Sub CheckModule([module] As PEModuleSymbol, moduleVersionId As Guid)
If [module] Is Nothing Then
Throw New ArgumentException($"No module found with MVID '{moduleVersionId}'", NameOf(moduleVersionId))
End If
End Sub
<Extension>
Friend Function ToCompilation(metadataBlocks As ImmutableArray(Of MetadataBlock)) As VisualBasicCompilation
Return VisualBasicCompilation.Create(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册