dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.95k stars 4.9k forks source link

Assembly.GetCallingAssembly() on XUnit has different behavior on linux than windows #8394

Open jsquire opened 1 year ago

jsquire commented 1 year ago

Issue Transfer

This issue has been transferred from the Azure SDK for .NET repository, #35554.

Please be aware that @DR9885 is the author of the original issue and include them for any questions or replies.

Details

Library name and version

dotnet-sdk-7.0

Describe the bug

When running in XUnit, the results are inconsistent for calling Assembly.GetCallingAssembly(). When trying to get the running library name. On Windows: Test.Library.Name On Linux: testhost

Code:

public class AssemblyUtil
{
      private static readonly Assembly Assembly = Assembly.GetCallingAssembly().GetName().Name
}

Test Code:

public class AssemblyUnitTest
{
    [Fact]
    public void TestNamespace()
    {
        var name = AssemblyUtil.AssemblyName;
        Assert.Equal("Test.Library.Name", name);
    }
}

Expected behavior

On Windows: Test.Library.Name On Linux: Test.Library.Name

Actual behavior

On Windows: Test.Library.Name On Linux: testhost

Reproduction Steps

Run XUnit, and simply call Assembly.GetCallingAssembly(), on windows and linux

Environment

No response

DR9885 commented 1 year ago

Also, here is the csproj, just in case.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <LangVersion>latest</LangVersion>
        <NoWarn>$(NoWarn)</NoWarn>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0-preview.2.23128.3" />
        <PackageReference Include="OpenTelemetry.Api" Version="1.4.0-rc.4" />
    </ItemGroup>

</Project>