Skip to content

[API Proposal]: Marshal.GetPInvokeErrorMessage() overload for localization #72546

Closed
@AaronRobinsonMSFT

Description

@AaronRobinsonMSFT

Background and motivation

Follow-up on #67872 for adding a localization overload.

The utility of this function is often for developer to log. However, the localization is dependent on the user's machine configuration, not the developers. It would be helpful for people for their logging utilities to be able to specify that locale and not rely on the user's machine.

User related conversation #40427 (comment)

API Proposal

namespace System.Runtime.InteropServices;

public partial class Marshal
{
    // Existing
    // public static int GetLastPInvokeError();
    // public static string GetLastPInvokeErrorMessage();
    // public static string GetPInvokeErrorMessage(int error);
+    public static string GetPInvokeErrorMessage(int error, CultureInfo cultureInfo);
}

There doesn't seem to be a strong need for an overload for public static string GetLastPInvokeErrorMessage(CultureInfo cultureInfo);, but that is an option.

API Usage

string presentToUser = Marshal.GetPInvokeErrorMessage(error, CultureInfo.CurrentUICulture);
string logForDev = Marshal.GetPInvokeErrorMessage(error, CultureInfo.CreateSpecificCulture("en-us"));

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions