Cant use msgbox inside paint event

Just got the weirdest OS exception
It makes some sense but its a brand new one to me

new desktop app
add Paint event to Window1
in there put

 msgbox "foo"

and run

here on 10.14.6 I get an OS level exception

[quote]Application Specific Information:
Crashing on exception: -[NSAlert runModal] may not be invoked inside of transaction begin/commit pair, or inside of transaction commit (usually this means it was invoked inside of a view’s -drawRect: method.)
[/quote]

I’ve altered my DebuggingSupport.Assert method to the following
This makes use of Kems M_String module but it would be easy to remove the one thing I use here

Public Sub Assert(condition as boolean, message as string)
  If condition = False Then
    
    #If DebugBuild Then
      
      Dim skipShowingMsgBox As Boolean
      #If TargetMacOS
        Try
          Raise New nilobjectException
        Catch noe As nilobjectexception
          Dim s() As String = noe.Stack
          For i As Integer = 0 To s.ubound
            Dim eventName As String = NthField(s(i),".",2)
            If eventName.StartsWith_MTC("Event_Paint%%o") Then
              skipShowingMsgBox = True
              Exit
            End If
          Next
        End Try
      #EndIf
      
      If skipShowingMsgBox = False Then
        MsgBox "Assertion failed" + EndOfLine + message
      End If
      
      // now we can go see what caused the assertion in the debugger
      // by walking the stack
      Break 
      
    #Else
      
      System.Log System.LogLevelCritical, "Assertion failed " + EndOfLine + message
      
    #EndIf
    
  End If
End Sub