question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with .net core and portable format

See original GitHub issue

As you may know OpenCover uses Mono.Cecil to leverage the reading of PDB files and I was hoping that the latest release would resolve the issue identified with handling .net core (https://github.com/OpenCover/opencover/issues/610)

I upgraded to 0.9.6.3 through nuget (as it appeared work on portable format had been done between the the 0.9.6.1 and 0.9.6.3 releases) but the library is throwing an OutOfMemoryException(“Array dimensions exceeded supported range.”).

   at Microsoft.Cci.Pdb.MsfDirectory..ctor(PdbReader reader, PdbFileHeader head, BitAccess bits)
   at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Dictionary`2& tokenToSourceMapping, String& sourceServerData, Int32& age, Guid& guid)
   at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
   at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
   at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
   at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
   at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
   at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters)
   at OpenCover.Framework.Symbols.CecilSymbolManager.LoadSourceAssembly() in C:\Projects\opencover.git\working\main\OpenCover.Framework\Symbols\CecilSymbolManager.cs:line 126

I tried to investigate myself but the mainline has moved on and broken backward compatibility (SequencePoint related) and I can’t tell from your git history nor your releases which commit aligns with the nuget package 0.9.6.3.

Can you help by either

  1. resolution of the issue
  2. identify which commit was used to build the 0.9.6.3 release so that I can investigate the issue myself.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jbevaincommented, Jul 23, 2016

@sawilde hey Shaun,

As you mentioned, in .NET Core, the pdb format changed. There’s nothing in 0.9.6 to handle the portable pdb files. What’s happening is that Cecil is trying to read a portable pdb file with the native pdb reader, and the native pdb reader crashes while misinterpreting the file. This particular exception has been fixed in master through #279.

To answer your question, the 0.9.6 nuget is maintained through the 0.9.6-nuget branch. 0.9.6.3 has been built off 0f397dbf7059eb1efdeeffe70bdaf13f99c2b447.

Now, to really fix the .NET Core scenario, you’re going to need support for portable pdbs which are in master and aimed at being released through 0.10 based on the master, which is now fairly stable.

There are breaking changes in 0.10 however. To help you update, please find bellow the current breaking change log:

Custom Attributes on interface implementation for winmd files

We used to have:

class TypeDefinition {
   public Collection<TypeReference> Interfaces { get; }
}

We now have:

class TypeDefinition {
   public Collection<InterfaceImplementation> Interfaces { get; }
}

class InterfaceImplementation {
  public TypeReference InterfaceTypes { get; }
  public Collection<CustomAttribute> CustomAttributes { get; }
}

That’s an easy change.

Lower Memory Usage

I’ve merged this branch, meaning that by default a ModuleDefinition keeps an open handle on its file and needs to be disposed. The default behavior for a DefaultAssemblyResolver, which is caching, is to dispose all cached assemblies when the resolver is disposed.

You may override that by setting the InMemory = true of the ReaderParameters, but that will lead to more memory fragmentation.

Because of this, if you were previously reading and writing an assembly on the same file, you need to change how you read and write your assembly to:

// ReaderParameters { ReadWrite = true } is necessary to later write the file
using (var module = ModuleDefinition.ReadModule(file, new ReaderParameters { ReadWrite = true })) 
{
    // Modify the assembly

    module.Write (); // Write to the same file that was used to open the file
}

Portable Pdb Support

This is a large change that introduces support for the new portable pdb information. The nice thing is that when users transition to the new format, all features are supported, and you can debug a rewritten assembly without loss of debug information.

It also simplifies quite a bit the debug symbol reader / writer. For 0.11, I’ll look into improving the native pdb story.

Things that went away:

Instruction.SequencePoint VariableReference.Name

The information moved to MethodDefinition.DebugInformation. You can use instead:

MethodDebugInformation.GetSequencePoint(Instruction) MethodDebugInformation.TryGetName(VariableDefinition, out string)

0reactions
jbevaincommented, Sep 28, 2017

@facedbook there’s nothing builtin. The Portable Pdb support uses the Cecil object model to represent debug symbol.

You need to work with the method.DebugInformation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"PDB format is not supported" with .NET portable ...
The last couple of days I've been hunting down a problem - with the conclusion: My Visual Studio 2017 debugger can't work with...
Read more >
NET application publishing overview
Learn about the ways to publish a .NET application. .NET can publish platform-specific or cross-platform apps. You can publish an app as ...
Read more >
Instrumenting .Net Core 2.0 console app "File contains no ...
Instrumentation works if you don't use the Portable PDB format for the .Net Core assembly you are attempting to instrument.
Read more >
Portable PDB format support
Repro: I have a .NET 4.5 application that references a class library project that targets multiple framework versions (.NET Core, .NET Standard, ...
Read more >
Upgrading an existing .NET project files to the lean new ...
In Visual Studio 2017 and .NET Core 2 (and beyond) the csproj format is MUCH MUCH leaner. There's a lot of smart defaults,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found