Skip to content

.NET 11 regression: LPArray ArraySubType.Currency passes decimal storage without currency conversion #134575

Closed

Description

@MichalStrehovsky

Description

An LPArray parameter explicitly marked ArraySubType=UnmanagedType.Currency is passed with the managed decimal representation instead of the native CY representation. The native callee reads 0 for a managed value of 1m on .NET 11; the same binary returns the correct scaled currency value 10000 on .NET 10.

Reproduction steps

Create an empty directory outside the runtime repository and save the following as Repro.csproj and Program.cs. No external native library or NuGet package is required; the native-facing entry point is provided through UnmanagedCallersOnly or Windows built-in COM interop.

Repro.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

Program.cs

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

internal static unsafe class Program
{
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    private delegate long ReadCurrency([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Currency)] decimal[] values);

    private static int Main()
    {
        Console.WriteLine(RuntimeInformation.FrameworkDescription);
        if (!OperatingSystem.IsWindows())
        {
            Console.WriteLine("Requires Windows built-in Currency marshalling.");
            return 2;
        }

        var read = Marshal.GetDelegateForFunctionPointer<ReadCurrency>(
            (nint)(delegate* unmanaged[Cdecl]<long*, long>)&ReadFirst);
        long actual = read([1m]);
        const long Expected = 10000;
        Console.WriteLine($"Expected CY value: {Expected}; actual: {actual}");
        Console.WriteLine(actual == Expected ? "PASS" : "BUG: decimal storage was passed instead of converted currency.");
        return actual == Expected ? 0 : 1;
    }

    [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
    private static long ReadFirst(long* values) => values[0];
}

Build once with dotnet build Repro.csproj. Run the generated apphost against the two runtimes:

$env:DOTNET_ROLL_FORWARD_TO_PRERELEASE = '1'
$env:DOTNET_ROLL_FORWARD = 'LatestPatch'
& .\bin\Debug\net10.0\Repro.exe

$env:DOTNET_ROLL_FORWARD = 'LatestMajor'
& .\bin\Debug\net10.0\Repro.exe

These commands assume the apphost resolves to a .NET installation containing the tested .NET 10 and .NET 11 runtimes, with no newer major version. If needed, set DOTNET_ROOT to that installation. Check the framework version printed by the program rather than assuming which runtime was selected. Remove the temporary roll-forward environment variables after the comparison.

Expected behavior

ArraySubType.Currency must convert each decimal to a native eight-byte CY value. For 1m the native value is 10000.

.NET 10 output:

.NET 10.0.5
Expected CY value: 10000; actual: 10000
PASS

Actual behavior

.NET 11 output from the same compiled program:

.NET 11.0.0-rc.1.26420.103
Expected CY value: 10000; actual: 0
BUG: decimal storage was passed instead of converted currency.

Regression

Confirmed by running the same net10.0-targeted program on .NET 10.0.5 and .NET 11.0.0-rc.1.26420.103.

The exact introducing commit has not been established by a runtime build-and-bisect. The implementation observations below are based on source inspection.

Configuration

  • Windows x64, CoreCLR, built-in runtime marshalling.
  • Passing runtime: .NET 10.0.5.
  • Failing runtime: .NET 11.0.0-rc.1.26420.103.
  • Compiled with SDK 11.0.100-rc.1.26420.103, targeting net10.0.
  • The repository runtime was not rebuilt for this comparison. Linux, ARM64, x86, Mono, NativeAOT, and source-generated marshalling were not tested.

Implementation observations

ArrayMarshalInfo selects VT_CY for the explicit Currency subtype. However, the pinning predicate checks the separate elementNativeType discriminator and the managed element's blittability without excluding this conversion-requiring VARTYPE. The decimal array can therefore bypass CurrencyArrayElementMarshaler entirely. See currency subtype selection, pinning eligibility, and required currency conversion.

This is the opposite of a lost-pinning case: this explicitly requested conversion must not be replaced by pinning.

Note

This report was prepared with GitHub Copilot assistance; the included runtime outputs were reproduced locally.

Activity

  1. added
    untriaged
    on Sep 24, 2026
  2. dotnet-policy-service commented on Sep 24, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  3. added a commit that references this issue on Sep 28, 2026
    a304043
  4. added this to the 11.0.0 milestone on Oct 2, 2026
  5. removed
    untriaged
    on Oct 2, 2026
  6. added a commit that references this issue on Oct 5, 2026
    6634a7c
  7. added a commit that references this issue on Oct 8, 2026
    5431039
  8. locked and limited conversation to collaborators on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions