Skip to content

[mono] Empty string custom arg values should use string.Empty #58022

@uweigand

Description

@uweigand

Description

Running the aspnetcore Microsoft.AspNetCore.Server.Kestrel.Core.Tests unit tests on Mono fails with multiple errors along the lines of:

    Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.StartLineTests.AuthorityForms(rawTarget: "localhost", path: "", query: "") [FAIL]
      Assert.Same() Failure
      Expected:
      Actual:
      Stack Trace:
        /home/uweigand/aspnetcore/src/Servers/Kestrel/Core/test/StartLineTests.cs(478,0): at Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.StartLineTests.AuthorityForms(String rawTarget, String path, String query)
        /home/uweigand/runtime/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs(370,0): at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

This is because the test makes the assumption that if a custom argument has an empty string as default argument, that string will be reference-equal to string.Empty. This is true on CoreCLR but not on Mono.

Configuration

.NET 6 Preview7 re-built for the linux-s390x target (using the Mono runtime by default).

Regression?

No.

Other information

The Mono code path in load_cattr_value (src/mono/mono/metadata/custom-attrs.c) will always allocate a new string object, even if the string is empty. Adding a special case to use string.Empty for zero-length strings fixes the test case. I'll post a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions