Skip to content

Fix BadImageFormatException #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
@@ -173,11 +173,7 @@ private void CalculateCoverage()
continue;

bool isBranch = info[0] == "B";

if (!result.Documents.TryGetValue(info[1], out var document))
{
continue;
}
var document = result.Documents.ElementAt(int.Parse(info[1])).Value;

int start = int.Parse(info[2]);
int hits = int.Parse(info[4]);
16 changes: 14 additions & 2 deletions src/coverlet.core/Instrumentation/Instrumenter.cs
Original file line number Diff line number Diff line change
@@ -175,19 +175,25 @@ private void InstrumentIL(MethodDefinition method)

private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, SequencePoint sequencePoint)
{
int documentIndex = 0;
if (!_result.Documents.TryGetValue(sequencePoint.Document.Url, out var document))
{
document = new Document { Path = sequencePoint.Document.Url };
documentIndex = _result.Documents.Count;
_result.Documents.Add(document.Path, document);
}
else
{
documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path);
}

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

string marker = $"L,{document.Path},{sequencePoint.StartLine},{sequencePoint.EndLine}";
string marker = $"L,{documentIndex},{sequencePoint.StartLine},{sequencePoint.EndLine}";

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

private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, BranchPoint branchPoint)
{
int documentIndex = 0;
if (!_result.Documents.TryGetValue(branchPoint.Document, out var document))
{
document = new Document { Path = branchPoint.Document };
documentIndex = _result.Documents.Count;
_result.Documents.Add(document.Path, document);
}
else
{
documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path);
}

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

string marker = $"B,{document.Path},{branchPoint.StartLine},{branchPoint.Ordinal}";
string marker = $"B,{documentIndex},{branchPoint.StartLine},{branchPoint.Ordinal}";

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