@@ -482,7 +482,8 @@ internal static EventLogHandle EvtGetPublisherMetadataPropertyHandle(EventLogHan
482
482
public static string EvtFormatMessage ( EventLogHandle handle , uint msgId )
483
483
{
484
484
int bufferNeeded ;
485
- bool status = UnsafeNativeMethods . EvtFormatMessage ( handle , EventLogHandle . Zero , msgId , 0 , null , UnsafeNativeMethods . EvtFormatMessageFlags . EvtFormatMessageId , 0 , null , out bufferNeeded ) ;
485
+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
486
+ bool status = UnsafeNativeMethods . EvtFormatMessage ( handle , EventLogHandle . Zero , msgId , 0 , null , UnsafeNativeMethods . EvtFormatMessageFlags . EvtFormatMessageId , 0 , emptyBuffer , out bufferNeeded ) ;
486
487
int error = Marshal . GetLastWin32Error ( ) ;
487
488
488
489
// ERROR_EVT_UNRESOLVED_VALUE_INSERT and its cousins are commonly returned for raw message text.
@@ -933,7 +934,8 @@ public static IList<object> EvtRenderBufferWithContextUserOrValues(EventLogHandl
933
934
public static string EvtFormatMessageRenderName ( EventLogHandle pmHandle , EventLogHandle eventHandle , UnsafeNativeMethods . EvtFormatMessageFlags flag )
934
935
{
935
936
int bufferNeeded ;
936
- bool status = UnsafeNativeMethods . EvtFormatMessage ( pmHandle , eventHandle , 0 , 0 , null , flag , 0 , null , out bufferNeeded ) ;
937
+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
938
+ bool status = UnsafeNativeMethods . EvtFormatMessage ( pmHandle , eventHandle , 0 , 0 , null , flag , 0 , emptyBuffer , out bufferNeeded ) ;
937
939
int error = Marshal . GetLastWin32Error ( ) ;
938
940
939
941
if ( ! status && error != UnsafeNativeMethods . ERROR_EVT_UNRESOLVED_VALUE_INSERT
@@ -985,11 +987,12 @@ public static IEnumerable<string> EvtFormatMessageRenderKeywords(EventLogHandle
985
987
{
986
988
IntPtr buffer = IntPtr . Zero ;
987
989
int bufferNeeded ;
990
+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
988
991
989
992
try
990
993
{
991
994
List < string > keywordsList = new List < string > ( ) ;
992
- bool status = UnsafeNativeMethods . EvtFormatMessageBuffer ( pmHandle , eventHandle , 0 , 0 , IntPtr . Zero , flag , 0 , IntPtr . Zero , out bufferNeeded ) ;
995
+ bool status = UnsafeNativeMethods . EvtFormatMessage ( pmHandle , eventHandle , 0 , 0 , null , flag , 0 , emptyBuffer , out bufferNeeded ) ;
993
996
int error = Marshal . GetLastWin32Error ( ) ;
994
997
995
998
if ( ! status )
@@ -1071,6 +1074,7 @@ public static string EvtRenderBookmark(EventLogHandle eventHandle)
1071
1074
public static string EvtFormatMessageFormatDescription ( EventLogHandle handle , EventLogHandle eventHandle , string [ ] values )
1072
1075
{
1073
1076
int bufferNeeded ;
1077
+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
1074
1078
1075
1079
UnsafeNativeMethods . EvtStringVariant [ ] stringVariants = new UnsafeNativeMethods . EvtStringVariant [ values . Length ] ;
1076
1080
for ( int i = 0 ; i < values . Length ; i ++ )
@@ -1079,7 +1083,7 @@ public static string EvtFormatMessageFormatDescription(EventLogHandle handle, Ev
1079
1083
stringVariants [ i ] . StringVal = values [ i ] ;
1080
1084
}
1081
1085
1082
- bool status = UnsafeNativeMethods . EvtFormatMessage ( handle , eventHandle , 0xffffffff , values . Length , stringVariants , UnsafeNativeMethods . EvtFormatMessageFlags . EvtFormatMessageEvent , 0 , null , out bufferNeeded ) ;
1086
+ bool status = UnsafeNativeMethods . EvtFormatMessage ( handle , eventHandle , 0xffffffff , values . Length , stringVariants , UnsafeNativeMethods . EvtFormatMessageFlags . EvtFormatMessageEvent , 0 , emptyBuffer , out bufferNeeded ) ;
1083
1087
int error = Marshal . GetLastWin32Error ( ) ;
1084
1088
1085
1089
if ( ! status && error != UnsafeNativeMethods . ERROR_EVT_UNRESOLVED_VALUE_INSERT
0 commit comments