@@ -251,7 +251,17 @@ public void Convert(PEReader peReader, Stream sourcePdbStream, Stream targetPdbS
251251
252252 var symSequencePoints = symMethod . GetSequencePoints ( ) . ToImmutableArray ( ) ;
253253
254- BlobHandle sequencePointsBlob = SerializeSequencePoints ( metadataBuilder , localSignatureRowId , symSequencePoints , documentIndex , out var singleDocumentHandle ) ;
254+ // add a dummy document:
255+ if ( documentIndex . Count == 0 && symSequencePoints . Length > 0 )
256+ {
257+ documentIndex . Add ( string . Empty , metadataBuilder . AddDocument (
258+ name : metadataBuilder . GetOrAddDocumentName ( string . Empty ) ,
259+ hashAlgorithm : default ( GuidHandle ) ,
260+ hash : default ( BlobHandle ) ,
261+ language : default ( GuidHandle ) ) ) ;
262+ }
263+
264+ BlobHandle sequencePointsBlob = SerializeSequencePoints ( metadataBuilder , localSignatureRowId , symSequencePoints , documentIndex , methodToken , out var singleDocumentHandle ) ;
255265
256266 metadataBuilder . AddMethodDebugInformation (
257267 document : singleDocumentHandle ,
@@ -1022,11 +1032,12 @@ private static LocalVariableHandle NextHandle(LocalVariableHandle handle) =>
10221032 private static LocalConstantHandle NextHandle ( LocalConstantHandle handle ) =>
10231033 MetadataTokens . LocalConstantHandle ( MetadataTokens . GetRowNumber ( handle ) + 1 ) ;
10241034
1025- private static BlobHandle SerializeSequencePoints (
1035+ private BlobHandle SerializeSequencePoints (
10261036 MetadataBuilder metadataBuilder ,
10271037 int localSignatureRowId ,
10281038 ImmutableArray < SymUnmanagedSequencePoint > sequencePoints ,
1029- Dictionary < string , DocumentHandle > documentIndex ,
1039+ IReadOnlyDictionary < string , DocumentHandle > documentIndex ,
1040+ int methodIndex ,
10301041 out DocumentHandle singleDocumentHandle )
10311042 {
10321043 if ( sequencePoints . Length == 0 )
@@ -1043,15 +1054,15 @@ private static BlobHandle SerializeSequencePoints(
10431054 // header:
10441055 writer . WriteCompressedInteger ( localSignatureRowId ) ;
10451056
1046- DocumentHandle previousDocument = TryGetSingleDocument ( sequencePoints , documentIndex ) ;
1057+ DocumentHandle previousDocument = TryGetSingleDocument ( sequencePoints , documentIndex , methodIndex ) ;
10471058 singleDocumentHandle = previousDocument ;
10481059
10491060 int previousOffset = - 1 ;
10501061 for ( int i = 0 ; i < sequencePoints . Length ; i ++ )
10511062 {
10521063 var sequencePoint = SanitizeSequencePoint ( sequencePoints [ i ] , previousOffset ) ;
10531064
1054- var currentDocument = documentIndex [ sequencePoint . Document . GetName ( ) ] ;
1065+ var currentDocument = GetDocumentHandle ( sequencePoint . Document , documentIndex , methodIndex ) ;
10551066 if ( previousDocument != currentDocument )
10561067 {
10571068 // optional document in header or document record:
@@ -1143,12 +1154,12 @@ private static SymUnmanagedSequencePoint SanitizeSequencePoint(SymUnmanagedSeque
11431154 return new SymUnmanagedSequencePoint ( offset , sequencePoint . Document , startLine , startColumn , endLine , endColumn ) ;
11441155 }
11451156
1146- private static DocumentHandle TryGetSingleDocument ( ImmutableArray < SymUnmanagedSequencePoint > sequencePoints , Dictionary < string , DocumentHandle > documentIndex )
1157+ private DocumentHandle TryGetSingleDocument ( ImmutableArray < SymUnmanagedSequencePoint > sequencePoints , IReadOnlyDictionary < string , DocumentHandle > documentIndex , int methodToken )
11471158 {
1148- DocumentHandle singleDocument = documentIndex [ sequencePoints [ 0 ] . Document . GetName ( ) ] ;
1159+ DocumentHandle singleDocument = GetDocumentHandle ( sequencePoints [ 0 ] . Document , documentIndex , methodToken ) ;
11491160 for ( int i = 1 ; i < sequencePoints . Length ; i ++ )
11501161 {
1151- if ( documentIndex [ sequencePoints [ i ] . Document . GetName ( ) ] != singleDocument )
1162+ if ( GetDocumentHandle ( sequencePoints [ i ] . Document , documentIndex , methodToken ) != singleDocument )
11521163 {
11531164 return default ( DocumentHandle ) ;
11541165 }
@@ -1157,6 +1168,28 @@ private static DocumentHandle TryGetSingleDocument(ImmutableArray<SymUnmanagedSe
11571168 return singleDocument ;
11581169 }
11591170
1171+ private DocumentHandle GetDocumentHandle ( ISymUnmanagedDocument document , IReadOnlyDictionary < string , DocumentHandle > documentIndex , int methodToken )
1172+ {
1173+ string name ;
1174+ try
1175+ {
1176+ name = document . GetName ( ) ;
1177+ }
1178+ catch ( Exception )
1179+ {
1180+ ReportDiagnostic ( PdbDiagnosticId . InvalidSequencePointDocument , methodToken ) ;
1181+ return default ( DocumentHandle ) ;
1182+ }
1183+
1184+ if ( documentIndex . TryGetValue ( name , out var handle ) )
1185+ {
1186+ return handle ;
1187+ }
1188+
1189+ ReportDiagnostic ( PdbDiagnosticId . InvalidSequencePointDocument , methodToken ) ;
1190+ return default ( DocumentHandle ) ;
1191+ }
1192+
11601193 private static void SerializeDeltaLinesAndColumns ( BlobBuilder writer , SymUnmanagedSequencePoint sequencePoint )
11611194 {
11621195 int deltaLines = sequencePoint . EndLine - sequencePoint . StartLine ;
0 commit comments