Jump to content

PaintDotNet.Document problem


Recommended Posts

Good morning everyone,

I am using Paint.NET v3.5.8 (Final Release build 3.58.4081.24580)

I have a number of PDN files which are geographic maps. They define the locations of maritime shipping lanes. A large number of shipping lanes are defined in this way and each lane is defined on a separate layer. In practice this means that I have a large number of PDN files each of which has a large number of layers. Other processes that are not connected/associated with Paint.Net derive their location data from these individual layers when they are saved as .BMP files.

I have downloaded LayerSaver which works as intended but I end up with a large, unstructured collection of BMP files. I am developing a mechanism (a C# app) for making layers more directly available to code which uses the lane definition created in Paint.Net.

But things have come unstuck right at the beginning. The code file which sets this up follows. In summary, there is a serialization problem. I am not sure what I'm missing. The substantive code (the two lines in SaveLayers()) is extracted from LayerSaver source code. The LayerSaver executable works just fine so it appears that I'm not declaring something that I need.

Any ideas anyone? The complete (I hope) information follows.



These PaintDotNet DLLs are included in the References list:





which also includes:






Entire code (.cs) file is:

namespace LayerManager.PdnFile




using System;

using System.Collections;

using System.Text;

using System.IO;

using PaintDotNet;

using PaintDotNet.IO;


using PDN_DOCUMENT = PaintDotNet.Document;



public class Class


private string _FileName;


public Class(string file_name)


_FileName = file_name;



public void SaveLayers()


///_FileName points to a multi-layer .pdn file.

///This line succeeds ... but ...

FileStream fs = new FileStream( _FileName, FileMode.Open, FileAccess.Read );

///... this line fails

PDN_DOCUMENT pdn_document = PDN_DOCUMENT.FromStream( fs );


The preceding line fails with:

A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in PaintDotNet.Core.dll

System.Runtime.Serialization.SerializationException was unhandled

Message="Exception thrown by worker thread"


Stack msgs that refer to Paint.Net code are:


at PaintDotNet.MemoryBlock.PaintDotNet.IDeferredSerializable.FinishDeserialization(Stream input, DeferredFormatter context) in D:\src\pdn\pdn_35x\src\Core\MemoryBlock.cs:line 928

at PaintDotNet.DeferredFormatter.FinishDeserialization(Stream input) in D:\src\pdn\pdn_35x\src\Core\DeferredFormatter.cs:line 116

at PaintDotNet.Document.FromStream(Stream stream) in D:\src\pdn\pdn_35x\src\Data\Document.cs:line 1490





Link to comment
Share on other sites

This is not really a query for this (troubleshooting) section. I'll move it to the Plugin Developers forum for you.

You should be aware that you are unlikely to get any support for a standalone app.

Link to comment
Share on other sites

Good morning EER,

Thanks for putting my query in the right place. This is my 1st post on this this site so I wasn't really sure where to put it and I thought that someone might sort it out -- which you have done and for which I am grateful.

Thanks also for your observation. It makes sense but I thought there might be someone out there who could say "You need a reference to this-or-that DLL and if you don't have it you can down load it here...".

BTW for what I'm doing PDN has been invaluable. Nice piece of work. Well done. Light years beyond Paint.

The downside is that since I'm (at least potentially) creating shipping lanes that connect every port on the planet to every other port, I absolutely must have programmatic way of managing the layers without 'hand' intervention or I'm going to spend the rest of my life drawing lines on bitmaps, saving, exporting, importing... you get the idea. Not a very enticing prospect, I'm sure you would agree.

Thanks again,


Link to comment
Share on other sites

There is currently no supported API for working with Paint.NET or its data formats, aside from what is provided for plugins when they are running inside of Paint.NET.

Paint.NET is not licensed for use except as an application, and its DLLs may not be redistributed. You may not use them for business purposes, which is what it sounds like you're doing. Paint.NET is not designed to be an image processing API for other applications, and such use is not permitted by the license.

I'm sorry, but I have to close this thread. Please do not ask for further assistance.

Thread Closed

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

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


Link to comment
Share on other sites

This topic is now closed to further replies.

  • Create New...