From b0bf0b684af7a1083868331861469a3f268326a8 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 18 May 2024 16:33:06 -0400 Subject: [PATCH] .Net: Fix ArgumentNullException from TextPlugin.Uppercase/Lowercase on .NET Framework (#6324) On .NET Framework, a null CultureInfo triggers an ArgumentNullException. --- dotnet/src/Plugins/Plugins.Core/TextPlugin.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dotnet/src/Plugins/Plugins.Core/TextPlugin.cs b/dotnet/src/Plugins/Plugins.Core/TextPlugin.cs index c145a7e8bfa9..842099709fc3 100644 --- a/dotnet/src/Plugins/Plugins.Core/TextPlugin.cs +++ b/dotnet/src/Plugins/Plugins.Core/TextPlugin.cs @@ -41,7 +41,8 @@ public sealed class TextPlugin /// An object that supplies culture-specific casing rules. /// The converted string. [KernelFunction, Description("Convert a string to uppercase.")] - public string Uppercase(string input, CultureInfo? cultureInfo = null) => input.ToUpper(cultureInfo); + public string Uppercase(string input, CultureInfo? cultureInfo = null) => + input.ToUpper(cultureInfo ?? CultureInfo.CurrentCulture); /// /// Convert a string to lowercase. @@ -50,7 +51,8 @@ public sealed class TextPlugin /// An object that supplies culture-specific casing rules. /// The converted string. [KernelFunction, Description("Convert a string to lowercase.")] - public string Lowercase(string input, CultureInfo? cultureInfo = null) => input.ToLower(cultureInfo); + public string Lowercase(string input, CultureInfo? cultureInfo = null) => + input.ToLower(cultureInfo ?? CultureInfo.CurrentCulture); /// /// Get the length of a string. Returns 0 if null or empty