Sign in to follow this  
Followers 0
Rick Brewster

HOW TO: Debug your plugin!

22 posts in this topic

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.

1

Share this post


Link to post
Share on other sites

Thank you so much, Rick, I only have the Express version, I will try this (should work as well).

EDIT: It doesn't work with Express version! :cry:

EDIT2: Could you add the texts so we could copy/paste (We can't do it from the screenshots).

0

Share this post


Link to post
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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

@SeriousSam

Thanks for this info.

I'm able to build/debug the DLL and run the Paint.net program.

But, I can't see any effect in the effects menu... So I can't run mine for debugging...

I've checked the paths and everything...

0

Share this post


Link to post
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.

0

Share this post


Link to post
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...)

0

Share this post


Link to post
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.

0

Share this post


Link to post
Share on other sites

Ok, now I get it working properly... I've first changed the .csproj because I didn't find .csproj.user

Then the .csproj.user has been created and I made the changes you described...

All plugins are here, and no error log in the file menu...

Thank you for your help.

0

Share this post


Link to post
Share on other sites
This is what I got when I went to Debug*

I'm guessing you're using the express edition? In which case, try SeriousSam's suggestion.

0

Share this post


Link to post
Share on other sites

Part yes. I am but this is Visual Basic I'm running. Is there help for visual basic?

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Side note: For debugging, see http://tinyurl.com/6lnldc.

If your project is already a "class library," then when you build the project a DLL will be created in Documents\Visual Studio 2008\Projects\{Your Project Name}\bin\{Release or Debug}.

0

Share this post


Link to post
Share on other sites

Can someone help me? I am using the Express Edition. So I tried to follow SeriousSam's suggestions, but when I open up the .csproj.user file in notepad the only line is see is:

So is it possible for me to be able to debug with what I have? Thanks in advance.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
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.

0

Share this post


Link to post
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.

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0