Dynamically creating PDI files from C# code

Discussion created by Steve_Clay on Jul 4, 2012
Latest reply on Jul 5, 2012 by Steve_Clay

Hello all,


I have a C# console app which opens up an empty display file in ProcessBook, adds some text to it and saves the new pdi file.  This small proof of concept app works fine.  The PDI file that gets produced is just what I expected to see.  However, when I close the ProcessBook application from the C# code I get the following error message:




Example Code shown below.  It is the last statement (line 48) "app.Close();" that causes the above error.  Any insight / help would be greatly appreciated. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using PBObjLib;
using PBSymLib;

namespace Generate_ProcessBook_Pages
    class Program
        static void Main(string[] args)
            PBObjLib.Application app = new PBObjLib.Application();
            PBObjLib.Display disp = app.Displays.Open(@"C:\Temp\PDI\POC\Temp.PDI", false);
            PBSymLib.Text pbText = (PBSymLib.Text)disp.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolText, System.Reflection.Missing.Value);

            pbText.Name = "lblText";
            pbText.Contents = "Dynamically added text";

            //  Set background colour to "none"
            pbText.BackgroundColor = -1;

            PBSymLib.IDualFont pbFont = pbText.Font;
            pbFont.Name = "Arial";
            pbFont.Size = 16;
            pbFont.Bold = false;
            pbFont.Italic = false;
            pbFont.Underline = false;
            pbText.LineColor = ColorTranslator.ToOle(ColorTranslator.FromHtml("#000000"));
            pbText.EnableScript = true;
            pbText.Left = 10 - 15000;
            pbText.Top = 15000 - 10;
            pbText.Selected = false;

            //Tidy up;
            pbFont = null;
            pbText = null;

            string fileName = @"C:\Temp\PDI\POC\saved_file.pdi";

            disp.SaveAs(fileName, PBObjLib.pbpdFILEFORMAT.pbpdFormatDisplay);