dotnet / dotnet/core

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

Open
#8,394 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PowerShell
Stars
22k
Forks
4.9k
Avg merge
5d 5h
Merged PRs (30d)
29

Description

# Issue Transfer

This issue has been transferred from the Azure SDK for .NET repository, [#35554](https://github.com/Azure/azure-sdk-for-net/issues/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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.