diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs index 5a6101da76257a..e4cebc7c2e1da2 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs +++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs @@ -967,7 +967,13 @@ public static string EvtFormatMessageRenderName(EventLogHandle pmHandle, EventLo EventLogException.Throw(error); } - int len = bufferNeeded - 1; // buffer includes null terminator + + // buffer may include null terminators + int len = bufferNeeded; + while (len > 0 && buffer[len - 1] == '\0') + { + len--; + } if (len <= 0) return string.Empty; diff --git a/src/libraries/System.Diagnostics.EventLog/tests/EventLogMessagesTests.cs b/src/libraries/System.Diagnostics.EventLog/tests/EventLogMessagesTests.cs index c9fbaebdc4906d..0585a690e103ed 100644 --- a/src/libraries/System.Diagnostics.EventLog/tests/EventLogMessagesTests.cs +++ b/src/libraries/System.Diagnostics.EventLog/tests/EventLogMessagesTests.cs @@ -4,7 +4,6 @@ using System.Diagnostics.Eventing.Reader; using System.IO; using System.Reflection; -using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; using Xunit; @@ -50,10 +49,7 @@ public unsafe void CanFormatMessage(uint messageId) } } - public static bool HasAssemblyFilesIsElevatedAndSupportsEventLogs => PlatformDetection.HasAssemblyFiles && Helpers.IsElevatedAndSupportsEventLogs; - - [ConditionalFact(nameof(HasAssemblyFilesIsElevatedAndSupportsEventLogs))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/88224", typeof(PlatformDetection), nameof(PlatformDetection.IsWindows10Version22000OrGreater))] + [ConditionalFact(typeof(Helpers), nameof(Helpers.HasAssemblyFilesIsElevatedAndSupportsEventLogs))] public void CanReadAndWriteMessages() { string messageDllPath = Path.Combine(Path.GetDirectoryName(typeof(EventLog).Assembly.Location), "System.Diagnostics.EventLog.Messages.dll"); diff --git a/src/libraries/System.Diagnostics.EventLog/tests/Helpers.cs b/src/libraries/System.Diagnostics.EventLog/tests/Helpers.cs index e47049dcdf71b2..d1b3ed22ae6faf 100644 --- a/src/libraries/System.Diagnostics.EventLog/tests/Helpers.cs +++ b/src/libraries/System.Diagnostics.EventLog/tests/Helpers.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; using System.Diagnostics.Eventing.Reader; using System.Threading; using Xunit; @@ -13,6 +12,7 @@ namespace System.Diagnostics.Tests { internal class Helpers { + public static bool HasAssemblyFilesIsElevatedAndSupportsEventLogs => PlatformDetection.HasAssemblyFiles && IsElevatedAndSupportsEventLogs; public static bool NotElevatedAndSupportsEventLogs { get => !AdminHelpers.IsProcessElevated() && SupportsEventLogs; } public static bool IsElevatedAndSupportsEventLogs { get => AdminHelpers.IsProcessElevated() && SupportsEventLogs; } public static bool SupportsEventLogs { get => PlatformDetection.IsNotWindowsNanoNorServerCore && PlatformDetection.IsNotWindowsIoTCore; } diff --git a/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj b/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj index 39089edfa7b2b5..e3fb65148f8bb2 100644 --- a/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj +++ b/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent)-windows;$(NetFrameworkMinimum) true