How to: debug plugins in the shared environments

By | April 20, 2022

When debugging a plugin, I often use PluginExecutionExceptions to display debugging messages. But, of course, it all works great when my development environment (or the plugin) is relatively isolated. And it all falls apart when there are other people working in the same environment, and they suddenly start seeing those error messages.

image

There is a simple workaround, though. Basically, I want to see those error messages, but I don’t want anyone else to be affected by them, so I just need to make sure they will be displayed for my user id. Which is easy to do with the help of the function below:

public static void ThrowDebuggingError(IPluginExecutionContext context, string msg, string userId)
{
   if (context.InitiatingUserId == new Guid(userId))
   {
      throw new InvalidPluginExecutionException(msg);
   }
}

With this in place, I can now call ThrowDebuggingError, pass plugin context, message, and my userId, and that error will only be displayed when the plugin has been initiated by me.

It’s worth noting that “context.InitiatingUserId” might work better than “context.UserId” in the code above, since InitiatingUserId woud correspond to my user account id even if the plugin is configured to run in the context of the “System” (or other) user account.

Leave a Reply

Your email address will not be published. Required fields are marked *