Hi @DSilver4773, I just discovered a workaround for this that should work. It did when I tested it; you'll have to try it with your own rule and let me know if it works. Basically, you close the document by starting a new thread which instructs the document to close. Because it takes place in a different thread, the catastrophic error doesn't occur. Here's how to implement it:
(IMPORTANT EDIT: I did some testing after my original post and remembered that iLogic parameters whose value you set using "<Parameter Name> = <Value>" (where the parameter name shows up in blue) aren't actually written with the new values until the rule finishes execution. However, the "CloseDocument" thread causes the rule to exit prematurely, so this doesn't happen. So if you use the "blue parameters" method to modify parameters, you'll need to force those values to be written by calling "RuleParametersOutput", as I do below).
Sub Main()
' <your rule's code here>
' ...
' IMPORTANT: INCLUDE THESE LINES IF YOU WANT YOUR CHANGES TO BE SAVED.
RuleParametersOutput
ThisDoc.Save
' Close Document.
Call New System.Threading.Thread(AddressOf CloseDocument).Start
End Sub
Sub CloseDocument
ThisDoc.Document.Close(True)
End Sub