Jump to content

HOW TO: Debug your plugin!


Rick Brewster

Recommended Posts

If you've written a plugin DLL with Visual Studio, you probably know that you can't really debug a DLL by itself. This becomes a sticky point for developing a plugin: how do you debug it!? Visual Studio has excellent facilities for debugging when you are launching an EXE, but for your plugin DLL it's a little more confusing.

Note: These instructions do not pertain to CodeLab plugins.

The trick is to set up your project settings so that you are actually launching Paint.NET! In this post, I will show you how. I have used this myself while developing some of the plugins I've posted in the past (e.g., HD Photo).

I'll use the HD Photo plugin an example. You can get the source code for it by downloading the source code for Paint.NET v3.07: http://www.getpaint.net/download.html . It is in the "extras" folder. Edit: The source code has long since been taken down. Please do not ask for it. Thanks.

1. Open up your project file in Visual Studio. (This much should be obvious 8))

2. Right click on your project in the Solution Explorer and then click on Properties.

plugin_debugging_2.png

3. Click on the "Debug" tab.

plugin_debugging_3.png

4. Click the "Start external program" radio button, and fill in the path to the Paint.NET executable.

5. Make sure to fill in the Working Directory as well. After you complete steps 4 and 5, you should have this:

plugin_debugging_4.png

6. You will want to create a custom Post Build Event that will copy your plugin DLL to the appropriate location. Otherwise Paint.NET won't be able to find your plugin, or it will use an older version.

Like so:

plugin_debugging_6.png

(Naturally, if you are setting this up for an Effect plugin, make sure to copy it to the Effects directory, not the FileTypes directory!)

7. Set a breakpoint in your code. This isn't a requirement -- I am listing this for illlustration purposes. As you get better with the debugger, or if you're already a ninja, you will do whatever is necessary.

plugin_debugging_8.png

8. And then run Paint.NET with the Debug -> Start Debugging menu item.

plugin_debugging_7.png

Now when there is an exception in your plugin, you will be thrown in to the debugger instead of getting a crash dialog. You can then debug it using the standard Visual Studio debugging commands.

  • Upvote 3

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

What I did in express edition was to create a new effect in pdn source under PaintDotNet.Effects. Create the dialog for it ... etc. Then when you start the debugger, the dll is built with the core application and can be debugged.

When I am done debugging, I copy the render function to my dll solution. And I can make any minor adjustments and compile the dll.

Link to comment
Share on other sites

  • 1 year later...

This is how I was able to get debugging working with VS2008 C# Express Edition

What is missing from the express edition is the start external program option. However, it can still be set manually in the "*.csproj.user" file found in the project directory.

First I opened up the "*.csproj.user" file in notepad.

It looked like:

I added the following commands:

Program

C:\Program Files\Paint.NET\PaintDotNet.exe

C:\Program Files\Paint.NET\Effects

Make sure these paths are correct for your own system

This completes steps 1-5 from Rick's guide.

Next open the solution and set the post build event to copy the dll to the Paint.Net\Effects directory (Rick's Step 6)

With Vista I found it was necessary to run visual studio as an admin or the file copy in the post build would fail. Setting the run as admin flag in the VCSExpress.exe compatibility properties will cleared this up.

Happy debugging

Link to comment
Share on other sites

MadJik, if you open of the file menu do you see a menu item exclamation with that says "View Plugin Load Errors ..." errors? If this is there it will show a stack trace and you can figure out what is throwing an exception and why the plugin is not getting loaded. Also double check the plugin is copied to the effects directory when your project is built. Take a look at the date created of the file in the effects directory to make sure it is current. If you move the dll to the effects directory does it show up normally?

I had the wrong namespace when loading the embedded image for the icon in my project and this caused it to not load.

Link to comment
Share on other sites

When I change the output build folder, it corrupts my paint.net installation.

No more plugin is available in the menus. But the DLL are still in the effects folder!

I had to uninstall pdn, and delete the folder and the entries in the registry (regedit) to be able to reinstall a correct version.

____________________

I'm used to build in the default folder "bin\debug" or "bin\release". So I build a debug version in the "bin\debug" (the pdn run doesn't work) and manually copy the DLL to the effects folder, then I press F5 again, and then it's ok to debug! Yes!

(tricky, but it works...)

Link to comment
Share on other sites

MadJik, that is a tricky way to get debugging to work. I did not change the output directory or configuration for my project, it is still Bin\debug. This is different from changing the working directory.

Are you able to see the "View Plugin Load Errors ..." menu item when no plugins get loaded? This helped me a lot.

Either way, glad to see you have a work-around.

Link to comment
Share on other sites

  • 4 months later...

If you write plugins without a debugger the PDN crash log/plugin crash dialog will at least tell you which exception has been thrown if it crashes.

KaHuc.png
Link to comment
Share on other sites

  • 2 months later...

If you can't enable debugging and haven't already done this, copying the .PDB file over to the Effects folder as well will at least give you line numbers for crashes.

KaHuc.png
Link to comment
Share on other sites

  • 1 year later...

RE: Template for Plugin Development using Visual C# 2010 Express - Unsuccessful try!

Start with Madjic's Stars plugin source

Run through Visual C# 2010 Express conversion wizard - no errors or warnings

Change Assembly name and StaticName to V2

Change Build Events path to match my machine - C:\Program Files\Paint.Net\Effects

Add PaintDotNet.Base reference

Start Debugging (F5) runs nicely, copying the new DLL to the .Effects folder, and PDN starts up with no errors.

However, the V2 effect is not showing up in the Render effects list or any place else.

Setting break points in various places, the only hit is at StaticName->get.

Would appreciate any help with this conversion to C# 2010 Express or another template to use.

The goal is to produce a plugin with my design of the Dialog window.

TIA, PatrickL

Edited by pleabo
pleabosig.png

Link to comment
Share on other sites

Go to the Debug menu, then click Exceptions...

In that window, make sure that for the "Common Language Runtime Exceptions" item, that both the checkboxes for "thrown" and "user-unhandled" are checked. Then, re-run.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

I'm also using VS Express. If the *.dll is not showing up, you may have targeted .Net 4.0 when you need to target 3.5.

Go to the Solution Explorer double click Properties > Application tab. Under the Target Framework heading, choose .Net 3.5 from the dropdown list.

Save & rebuild.

note you may be prompted to close & reopen the project. Do so.

Link to comment
Share on other sites

Go to the Solution Explorer double click Properties > Application tab. Under the Target Framework heading, choose .Net 3.5 from the dropdown list.

Bingo! Thank you. Now I can have some fun.

PatrickL

pleabosig.png

Link to comment
Share on other sites

It can take a while to find that one ;) Glad it worked for you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...