Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

PDB/MDB loading fails if the symbol file is found in a different directory #833

Closed
4 of 25 tasks
pa-hobe opened this issue Aug 15, 2018 · 1 comment
Closed
4 of 25 tasks

Comments

@pa-hobe
Copy link

pa-hobe commented Aug 15, 2018

Please provide the following information when submitting an issue.

Where appropriate replace the [ ] with a [X]

My Framework

  • .NET 2
  • .NET 3.5
  • .NET 4
  • .NET 4.5
  • .NET 4.6
  • .NET 4.6.1
  • .NET 4.6.2
  • .NET Core 1.0.0
  • Something else

My Environment

  • Windows 7 or below (not truly supported due to EOL)
  • Windows 8
  • Windows 8.1
  • Windows 10
  • Windows 10 IoT Core
  • Windows Server 2012
  • Windows Server 2012 R2
  • Windows Server 2016

I have already...

  • repeated the problem using the latest commit 19ebe9c in the master branch of OpenCover.
  • repeated the problem using the latest stable release of OpenCover.
  • reviewed the usage guide and usage document.
  • have looked at the opencover output xml file in an attempt to resolve the issue.
  • reviewed the current issues to check that the issue isn't already known.

My issue is related to (check only those which apply):

  • no coverage being recorded
  • 32 or 64 bit support
  • feature request

Expected Behavior

If option --searchdirs is set and the PDB file is found, then the symbols should be loaded regardless of the symbol file location.

Actual Behavior

If the symbol file is in a different directory than the image file, then the symbols are not loaded and the assembly cannot be instrumented.

Steps to reproduce the problem:

Move the PDB file somewhere else and point --searchdirs to its directory.

Explanation of the bug:

Source directory: OpenCover.FrameWork.Symbols

CecilSymbolManager.LoadSourceAssembly() first tries to load the assembly assuming the PDB file is in the same directory as the module file. Otherwise FileNotFoundException is thrown and resolved using CecilSymbolManager.SearchForSymbolsAndLoad().

Here, SymbolFileHelper.FindSymbolFolder(...) will find the symbols file evaluating --searchdirs.
Also ReaderParameters is correctly initialized with the file stream of the symbols file.
The line

_sourceAssembly = AssemblyDefinition.ReadAssembly(ModulePath, parameters);

reads the assembly including the symbols according to the settings in parameters.
Then however, the symbols are loaded again:

if (_sourceAssembly != null)
{
   var symbolReader = parameters.SymbolReaderProvider
       .GetSymbolReader(_sourceAssembly.MainModule, _sourceAssembly.MainModule.FileName);
   _sourceAssembly.MainModule.ReadSymbols(symbolReader);
}

The problem is that function GetSymbolReader is called with the module file name. Mono.Cecil then looks for the symbol file in the same directory as the module file. GetSymbolReader has a different overload with a symbol stream as argument that fixes the issue:

.GetSymbolReader(_sourceAssembly.MainModule, parameters.SymbolStream);

The purpose of the second symbol loading eludes me. Removing the whole if block quoted above works as well.

Fix suggestion:

Removal of the if block at the end of method CecilSymbolManager.SearchForSymbolsAndLoad()
after ReadAssembly().

Best regards
Heiko

@sawilde sawilde added the medium label Jan 1, 2019
@sawilde
Copy link
Member

sawilde commented Jan 1, 2019

@hoiqs - thanks I'll have a look

@sawilde sawilde added this to the Release (Q1 2019) milestone Jan 6, 2019
@sawilde sawilde added the bug label Jan 6, 2019
sawilde added a commit to sawilde/opencover that referenced this issue Jan 12, 2019
@sawilde sawilde closed this as completed Jan 12, 2019
@OpenCover OpenCover locked as resolved and limited conversation to collaborators Jan 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants