StackOverflow exception when resolving TypeReference SqlDbType
See original GitHub issueHello,
I’m attempting to use the global tool to add code coverage to our code base. It’s a mix of .NET Framework 4.6.1 and .NET Standard 2.0.0 as far as unit tests are concerned, and the .NET Framework projects are not SDK-style. For the purposes of this test I did move them to SDK-style projects for testing but I saw this issue both with and without SDK-style .NET Framework projects. Unfortunately I can’t share sample code because the libraries being used are proprietary and I’m not sure which part is failing to replicate it in a smaller solution.
We have a list of projects: .NET Framework Unit Test 1 .NET Framework Library 20 .NET Framework Library 21 .NET Standard Library 31 .NET Standard Library 32 .NET Standard Library 33
Reference tree that works:
- NET Framework Unit Test 1
- NET Framework Library 21
Reference tree that breaks and I’m trying to solve:
- NET Framework Unit Test 1
- NET Framework Library 20
- NET Standard Library 31
- NET Standard Library 33
- NET Standard Library 32
- NET Standard Library 33
- NET Standard Library 31
- NET Framework Library 21
- NET Framework Library 20
When I build the solution I go to .NET Framework Unit Test 1’s output folder and I see all of the libraries DLLs and their PDBs. I check other output folders and the size of the PDBs match. When I run code coverage it seems to run into warnings and hangs.
coverlet C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\CoverletTestingLibraryTests.dll --target "dotnet" --targetargs "vstest C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\CoverletTestingLibraryTests.dll" --format cobertura --output "C:/Software"
The warning message I get is: “BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.” but it is not clear to me which PDB it is complaining about. These PDBs also aren’t portable ones, they are specified as full PDBs in the csproj.
Here is the full log up to the hang:
Instrumented module:C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetStandard.Library.31.dll
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
Instrumented module:C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetStandard.Library.32.dll
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
If I run the same command again it will output the same messages but instead of hanging it will continue to completion. The unit tests succeed but it only outputs coverage for 4 of the 5 modules. I assume that is because the previous run attempted to alter the PDBs, somehow failed, and the altered PDBs are no longer valid for one of the projects. I believe that because it claims the PDB is a public PDB when it is not: “Unable to instrument module: C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetFramework.Library.20.dll because : Could not find the ‘/NAMES’ stream: the PDB file may be a public symbol file instead of a private symbol file”.
Here is the full log of the second run:
PS C:\Users\cjewett> coverlet C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\CoverletTestingLibraryTests.dll --target "dotnet" --targetargs "vstest C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\CoverletTestingLibraryTests.dll" --format cobertura --output "C:/Software" --verbosity detailed
Instrumented module: 'C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetStandard.Library.31.dll'
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
Instrumented module: 'C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetStandard.Library.32.dll'
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
Unable to instrument module: C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetFramework.Library.20.dll because : Could not find the '/NAMES' stream: the PDB file may be a public symbol file instead of a private symbol file
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
Instrumented module: 'C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetStandard.Library.33.dll'
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
Instrumented module: 'C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\NetFramework.Library.21.dll'
Unable to instrument module: C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\Microsoft.SqlServer.Types.dll because : No symbol found for file: C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\Microsoft.SqlServer.Types.dll
Unable to instrument module: C:\Software\Tests\UnitTests\CoverletTestingLibraryTests\bin\Debug\net461\protobuf-net.dll, embedded pdb without local source files, [C:\code\protobuf-net\src\protobuf-net\obj\Release\net40\protobuf-net.Version.cs]
Microsoft (R) Test Execution Command Line Tool Version 16.6.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Test Run Successful.
Total tests: 2
Passed: 2
Total time: 1.6138 Seconds
Calculating coverage result...
Calculating the results worked. I just omitted here.
The assembly missing code coverage is .NET Framework 20 which is also the one it complains about having a public PDB instead of a private PDB. The reason that happens though is because the previous run froze. Any ideas what might be going on here? Also, what steps can I take to debug this locally and confirm why this happens so I can see if it is possible to replicate easily?
Thanks for taking a look!
Issue Analytics
- State:
- Created 3 years ago
- Comments:14

Top Related StackOverflow Question
@MarcoRossignoli Thanks for continuing this conversation. I’ve updated https://github.com/Cjewett/CoverletIssue with net48 reproduce steps. SqlDbType seems to resolve correctly now but SqlBulkCopyOptions does not and results in an endless loop. I’m going to mess around with Mono.Cecil and try to figure out how the NET_CORE symbol is set.
close for stale conversation, feel free to reopen if needed.