Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Pdb loading fail using System.Reflection.Metadata
bhugot
#1 Posted : Sunday, August 19, 2018 6:22:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/19/2018(UTC)
Posts: 9
Location: France

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Kiaora,

I met a problem with the il injection when using System.Reflection.Metadata it seem's the pdb file can't be read anymore.
This code is working in simple runner as in live unit testing but fail with ncrunch.

Code:

using System;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using Xunit;

namespace MetadataTests
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            using (var stream = File.OpenRead(typeof(UnitTest1).Assembly.Location))
            using (var reader = new PEReader(stream))
            {
                Func<string, Stream> streamProvider = p => new FileStream(p, FileMode.Open, FileAccess.Read);

                var metadata = reader.GetMetadataReader(MetadataReaderOptions.ApplyWindowsRuntimeProjections);
                var pdbLoaded = reader.TryOpenAssociatedPortablePdb(stream.Name, streamProvider, out var metadataReaderProvider,
                    out var pdbPath);
                Assert.True(pdbLoaded);
                var metadataSymbol = metadataReaderProvider.GetMetadataReader();
                var type = metadata.TypeDefinitions.Select(metadata.GetTypeDefinition).First(a => metadata.GetString(a.Name).Equals(nameof(UnitTest1)));
                
                var meta = type.GetMethods().Select(a => metadataSymbol.GetMethodDebugInformation(a)).ToList();

                var debug = meta.SelectMany(a => a.GetSequencePoints()).Select(a => a.Document).First();
                var docu = metadataSymbol.GetDocument(debug);

                var name = metadataSymbol.GetString(docu.Name);
                Assert.Contains("UnitTest1.cs", name);
            }
        }
    }
}
Remco
#2 Posted : Sunday, August 19, 2018 10:55:49 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

This is caused by NCrunch's current lack of support for portable PDBs. To compensate, the NCrunch build system automatically overrides your project settings so that the PDB generated for your project will always be a legacy Win32 PDB. This then allows NCrunch to properly read and manipulate the PDB file when it adds instrumentation.

Because System.Reflection.PortableExecution relies on the PDB being a portable (not legacy Win32), it's unable to read this PDB. So you'll likely get an exception when this code is run.

Implementing support for portable PDBs is a significant piece of work for NCrunch. We're hoping to find a way to handle this over the next year or so.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.028 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download