Skip to content
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

Dotcover code coverage fails with AspectInjector 2.6.1 but not with AspectInjector 2.6.0 #170

Closed
El-Gor-do opened this issue Dec 29, 2021 · 1 comment
Assignees
Labels

Comments

@El-Gor-do
Copy link

Create a solution with 2 projects - MyLibrary and MyLibrary.Tests - and create the following files:

MyLibrary\MyLibrary.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AspectInjector" Version="2.6.1" />
  </ItemGroup>
</Project>

MyLibrary\InjectBeforeAttribute.cs

using System;
using System.Reflection;

using AspectInjector.Broker;

namespace MyLibrary
{
    [Aspect(Scope.PerInstance)]
    [AttributeUsage(AttributeTargets.Method)]
    [Injection(typeof(InjectBeforeAttribute))]
    public class InjectBeforeAttribute : Attribute
    {
        [Advice(Kind.Before, Targets = Target.Public | Target.Method)]
        public void OnEntry(
            [Argument(Source.Instance)] object instance,
            [Argument(Source.Metadata)] MethodBase method,
            [Argument(Source.Arguments)] object[] args)
        {
            Console.WriteLine($"Injected before method {method.Name}");
        }
    }
}

MyLibrary\Helper.cs

namespace MyLibrary
{
    public class Helper
    {
        [InjectBefore]
        public string Run()
        {
            return "Hello world";
        }
    }
}

MyLibrary.Tests\MyLibrary.Tests.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="JetBrains.dotCover.CommandLineTools" Version="2021.3.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\MyLibrary\MyLibrary.csproj" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="JetBrains.dotCover.DotNetCliTool" Version="2021.3.2" />
  </ItemGroup>
</Project>

MyLibrary.Tests\HelperTests.cs

using Xunit;

namespace MyLibrary.Tests
{
    public class HelperTests
    {
        [Fact]
        public void RunTest()
        {
            Helper helper = new Helper();
            string s = helper.Run();
        }
    }
}

Open a command prompt in the MyLibrary.Tests directory and run Dotcover using this command line:

dotnet.exe dotcover test --dotCoverOutput="C:\temp\MyLibrary.Tests.dcvr" --dcLogFile="C:\temp\MyLibrary.Tests.dcvr.log" --dcFilters=+:module=MyLibrary

Dotcover fails with the following output:

[JetBrains dotCover] Coverage session finished with errors: Inconsistent PDB detected, too large offset in statement table
[location] = C:\BuildAgent\work\c87178d597890b6b\Profiler\Kernel\Windows\Native\Solution\core\src\IL\Var\ILMethodVar.cpp(53)
[function] = unsigned short __cdecl ILMethodVar::BeginInject(struct write_stream_iface *,unsigned int)
[token] = 06000001, MethodDef
[method name] = Run
[module name] = D:\dev\AspectInjectorDotcoverClash\MyLibrary.Tests\bin\Debug\net6.0\MyLibrary.dll
[type name] = MyLibrary.Helper.

If I change MyLibrary.csproj to use AspectInjector 2.6.0 then the Dotcover command line runs successfully:

[JetBrains dotCover] Coverage session finished [29/12/2021 14:27:50]
[JetBrains dotCover] Coverage results post-processing started [29/12/2021 14:27:50]
[JetBrains dotCover] Merging snapshots [29/12/2021 14:27:50]
[JetBrains dotCover] Snapshots merging finished [29/12/2021 14:27:50]
[JetBrains dotCover] Coverage results post-processing finished [29/12/2021 14:27:50]
@pamidur pamidur self-assigned this Jan 2, 2022
@pamidur pamidur added the bug label Jan 2, 2022
@pamidur
Copy link
Owner

pamidur commented Jan 2, 2022

Hi @El-Gor-do , thanks for reporting, I 'll take a look shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants