Jump to content


Photo

HOW TO: Debug your plugin!


21 replies to this topic

#1 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,549 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 26 May 2007 - 11:29 PM

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.
Posted Image

3. Click on the "Debug" tab.
Posted Image

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:
Posted Image

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:
Posted Image

(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.
Posted Image

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

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.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#2 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 27 May 2007 - 08:14 AM

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

#3 moc426

moc426
  • Members
  • 369 posts
  • Reputation:3

Posted 27 May 2007 - 01:38 PM

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

#4 SeriousSam

SeriousSam
  • Members
  • 19 posts
  • Reputation:1

Posted 08 April 2009 - 07:57 AM

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

#5 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 08 April 2009 - 03:58 PM

@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

#6 SeriousSam

SeriousSam
  • Members
  • 19 posts
  • Reputation:1

Posted 09 April 2009 - 03:13 AM

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

#7 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 09 April 2009 - 04:16 AM

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

#8 SeriousSam

SeriousSam
  • Members
  • 19 posts
  • Reputation:1

Posted 09 April 2009 - 08:14 AM

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

#9 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 09 April 2009 - 08:28 AM

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

#10 Paul

Paul
  • Members
  • 36 posts
  • LocationLost
  • Reputation:0

Posted 28 August 2009 - 05:52 AM

problem.png This is what I got when I went to Debug*
  • 0
Is it really nessecary to put text here? Thought not :D

Posted Image

#11 Simon Brown

Simon Brown
  • Members
  • 10,251 posts
  • Reputation:27

Posted 28 August 2009 - 12:18 PM

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
Posted Image

#12 Paul

Paul
  • Members
  • 36 posts
  • LocationLost
  • Reputation:0

Posted 28 August 2009 - 01:58 PM

Part yes. I am but this is Visual Basic I'm running. Is there help for visual basic?
  • 0
Is it really nessecary to put text here? Thought not :D

Posted Image

#13 Simon Brown

Simon Brown
  • Members
  • 10,251 posts
  • Reputation:27

Posted 28 August 2009 - 02:13 PM

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
Posted Image

#14 Paul

Paul
  • Members
  • 36 posts
  • LocationLost
  • Reputation:0

Posted 28 August 2009 - 02:15 PM

Oh one more question? How do you make it a DLL?
  • 0
Is it really nessecary to put text here? Thought not :D

Posted Image

#15 Simon Brown

Simon Brown
  • Members
  • 10,251 posts
  • Reputation:27

Posted 28 August 2009 - 02:18 PM

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
Posted Image

#16 APShredder

APShredder
  • Members
  • 1,319 posts
  • LocationMassachusetts
  • Reputation:1

Posted 26 November 2009 - 03:38 AM

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

#17 Simon Brown

Simon Brown
  • Members
  • 10,251 posts
  • Reputation:27

Posted 26 November 2009 - 04:03 PM

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
Posted Image

#18 pleabo

pleabo
  • Members
  • 23 posts
  • LocationArizona
  • Reputation:1

Posted 16 December 2010 - 02:07 PM

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, 16 December 2010 - 02:27 PM.

  • 0

Posted Image


#19 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,549 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 16 December 2010 - 06:47 PM

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
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#20 Ego Eram Reputo

Ego Eram Reputo

    2013 Proton Award Winner

  • Moderators
  • 7,724 posts
  • LocationNorth Canterbury, New Zealand
  • Reputation:593

Posted 17 December 2010 - 05:23 AM

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