Skip to content

Commit 748e071

Browse files
authored
Merge pull request #169 from tonerdo/fix-badimageformatexception
Fix BadImageFormatException
2 parents e03c2e2 + 3603e43 commit 748e071

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ private void CalculateCoverage()
173173
continue;
174174

175175
bool isBranch = info[0] == "B";
176-
177-
if (!result.Documents.TryGetValue(info[1], out var document))
178-
{
179-
continue;
180-
}
176+
var document = result.Documents.ElementAt(int.Parse(info[1])).Value;
181177

182178
int start = int.Parse(info[2]);
183179
int hits = int.Parse(info[4]);

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,25 @@ private void InstrumentIL(MethodDefinition method)
175175

176176
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, SequencePoint sequencePoint)
177177
{
178+
int documentIndex = 0;
178179
if (!_result.Documents.TryGetValue(sequencePoint.Document.Url, out var document))
179180
{
180181
document = new Document { Path = sequencePoint.Document.Url };
182+
documentIndex = _result.Documents.Count;
181183
_result.Documents.Add(document.Path, document);
182184
}
185+
else
186+
{
187+
documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path);
188+
}
183189

184190
for (int i = sequencePoint.StartLine; i <= sequencePoint.EndLine; i++)
185191
{
186192
if (!document.Lines.ContainsKey(i))
187193
document.Lines.Add(i, new Line { Number = i, Class = method.DeclaringType.FullName, Method = method.FullName });
188194
}
189195

190-
string marker = $"L,{document.Path},{sequencePoint.StartLine},{sequencePoint.EndLine}";
196+
string marker = $"L,{documentIndex},{sequencePoint.StartLine},{sequencePoint.EndLine}";
191197

192198
var pathInstr = Instruction.Create(OpCodes.Ldstr, _result.HitsFilePath);
193199
var markInstr = Instruction.Create(OpCodes.Ldstr, marker);
@@ -202,11 +208,17 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor
202208

203209
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, BranchPoint branchPoint)
204210
{
211+
int documentIndex = 0;
205212
if (!_result.Documents.TryGetValue(branchPoint.Document, out var document))
206213
{
207214
document = new Document { Path = branchPoint.Document };
215+
documentIndex = _result.Documents.Count;
208216
_result.Documents.Add(document.Path, document);
209217
}
218+
else
219+
{
220+
documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path);
221+
}
210222

211223
var key = (branchPoint.StartLine, (int)branchPoint.Ordinal);
212224
if (!document.Branches.ContainsKey(key))
@@ -223,7 +235,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor
223235
}
224236
);
225237

226-
string marker = $"B,{document.Path},{branchPoint.StartLine},{branchPoint.Ordinal}";
238+
string marker = $"B,{documentIndex},{branchPoint.StartLine},{branchPoint.Ordinal}";
227239

228240
var pathInstr = Instruction.Create(OpCodes.Ldstr, _result.HitsFilePath);
229241
var markInstr = Instruction.Create(OpCodes.Ldstr, marker);

0 commit comments

Comments
 (0)