@@ -482,7 +482,8 @@ internal static EventLogHandle EvtGetPublisherMetadataPropertyHandle(EventLogHan
482482 public static string EvtFormatMessage ( EventLogHandle handle , uint msgId )
483483 {
484484 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 ) ;
486487 int error = Marshal . GetLastWin32Error ( ) ;
487488
488489 // 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
933934 public static string EvtFormatMessageRenderName ( EventLogHandle pmHandle , EventLogHandle eventHandle , UnsafeNativeMethods . EvtFormatMessageFlags flag )
934935 {
935936 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 ) ;
937939 int error = Marshal . GetLastWin32Error ( ) ;
938940
939941 if ( ! status && error != UnsafeNativeMethods . ERROR_EVT_UNRESOLVED_VALUE_INSERT
@@ -985,11 +987,12 @@ public static IEnumerable<string> EvtFormatMessageRenderKeywords(EventLogHandle
985987 {
986988 IntPtr buffer = IntPtr . Zero ;
987989 int bufferNeeded ;
990+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
988991
989992 try
990993 {
991994 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 ) ;
993996 int error = Marshal . GetLastWin32Error ( ) ;
994997
995998 if ( ! status )
@@ -1071,6 +1074,7 @@ public static string EvtRenderBookmark(EventLogHandle eventHandle)
10711074 public static string EvtFormatMessageFormatDescription ( EventLogHandle handle , EventLogHandle eventHandle , string [ ] values )
10721075 {
10731076 int bufferNeeded ;
1077+ Span < char > emptyBuffer = [ '\0 ' ] ; // issue: https://github.com/dotnet/runtime/issues/100198
10741078
10751079 UnsafeNativeMethods . EvtStringVariant [ ] stringVariants = new UnsafeNativeMethods . EvtStringVariant [ values . Length ] ;
10761080 for ( int i = 0 ; i < values . Length ; i ++ )
@@ -1079,7 +1083,7 @@ public static string EvtFormatMessageFormatDescription(EventLogHandle handle, Ev
10791083 stringVariants [ i ] . StringVal = values [ i ] ;
10801084 }
10811085
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 ) ;
10831087 int error = Marshal . GetLastWin32Error ( ) ;
10841088
10851089 if ( ! status && error != UnsafeNativeMethods . ERROR_EVT_UNRESOLVED_VALUE_INSERT
0 commit comments