System.Exception: 'Error getting printers in DymoSDK

Rinaldo 396 Reputation points
2024-02-26T07:46:54.79+00:00

Hi members, I have an error while trying to print labels on a Dymo Labelwriter. The class works standalone in a simple form program but in a bigger program it fails. The error detail is: EntryPointNotFoundException: Cannot find entrypoint SpoolMon_AddListener in DLL PrintingSupportLibrary.dll. This exception was originally thrown at this call stack: DYMO.LabelAPI.Windows.Printers.SpoolerMonitorGateway.SpoolerMonitorGateway() in SpoolerMonitorGateway.cs DYMO.LabelAPI.Windows.PrinterDiscovery.WindowsDeviceDiscoveryAgent.CreateNewSpoolerMonitorGateway() in WindowsDeviceDiscoveryAgent.cs Ther class where this exception is:

using DymoSDK.Implementations;
using DymoSDK.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VoorraadBeheer.Classes
{
    class DymoPrinters
    {
        public List<IPrinter> DymoPrinterList;

        private IDymoPrinter tmpIDymoPrinter;
        private IDymoLabel tmpIDymoLabel;
        public void Initialize()
        {
            DymoSDK.App.Init();
            tmpIDymoPrinter = DymoPrinter.Instance;
            tmpIDymoLabel = DymoLabel.Instance;
            DymoPrinterList = tmpIDymoPrinter.GetPrinters().Result.ToList();<ERROR         }

        public string LoadLabelXml(string LabelPath)
        {
            tmpIDymoLabel.LoadLabelFromFilePath(LabelPath);
            return tmpIDymoLabel.XMLContent;
        }

        public IDymoLabel MakeLabelFromXml(string LabelXml)
        {
            tmpIDymoLabel.LoadLabelFromXML(LabelXml);
            return tmpIDymoLabel;
        }
        public bool PrintLabel(IDymoLabel label, string PrinterName, int amount = 1)
        {
            return tmpIDymoPrinter.PrintLabel(label, PrinterName, amount).Result;
        }


    }
}

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,846 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rinaldo 396 Reputation points
    2024-05-18T12:59:30.4733333+00:00

    The correct class that works:

                {
    
    using DymoSDK.Implementations;
    using DymoSDK.Interfaces;
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace VoorraadBeheer.Classes
    {
        public class DymoPrinters
        {
            public List<IPrinter> DymoPrinterList;
            public List<IPrinter> FullDymoPrinterList;
            private IDymoPrinter tmpIDymoPrinter;
            private IDymoLabel tmpIDymoLabel;
            public void Initialize()
            {
                //ref PresentationFramework + WindowsBase
                if (null == System.Windows.Application.Current)
                {
                    new System.Windows.Application();
                }
                DymoSDK.App.Init();
                tmpIDymoPrinter = DymoPrinter.Instance;
                tmpIDymoLabel = DymoLabel.Instance;
                FullDymoPrinterList = tmpIDymoPrinter.GetPrinters().Result.ToList();
                DymoPrinterList = new List<IPrinter>();
                foreach (IPrinter printer in FullDymoPrinterList)
                {
                    if (printer.IsConnected)
                    {
                        DymoPrinterList.Add(printer);
                    }
                }
            }
            public string LoadLabelXml(string LabelPath)
            {
                tmpIDymoLabel.LoadLabelFromFilePath(LabelPath); // labelname and path
                return tmpIDymoLabel.XMLContent;
            }
            public IDymoLabel MakeLabelFromXml(string LabelXml)
            {
                tmpIDymoLabel.LoadLabelFromXML(LabelXml);
                return tmpIDymoLabel;
            }
            public bool PrintLabel(IDymoLabel label, string PrinterName, int amount = 1)
            {
                return tmpIDymoPrinter.PrintLabel(label, PrinterName, amount).Result;
            }
            public async Task <int> GetRemainingLabels(string PrinterName)
            {
                rollstatus = string.Empty;
                labelsremaining = 0;
                labelname = string.Empty;
                var tmpi = await DymoPrinter.Instance.GetRollStatusInPrinter(PrinterName);
                if (tmpi != null)
                {
                    rollstatus = tmpi.RollStatus.ToString();
                    labelsremaining = Convert.ToInt32(tmpi.LabelsRemaining);
                    labelname = tmpi.Name;
                    return labelsremaining;
                }
                return -1;
            }
                
                
                
            
        public string rollstatus { get; set; }
        public int labelsremaining { get; set; }
        public string labelname { get; set; }
        }
    }
    
    

  2. Rinaldo 396 Reputation points
    2024-05-18T13:48:41.5933333+00:00

    For I forget, the init if the class and members. Ask me if you don't get it at work

       public partial class DymoBarcodePrinter : Form
       {
     DymoPrinters myDymoPrinters;
     
     IDymoLabel tmpLabel;
           private void DymoBarcodePrinter_Load(object sender, EventArgs e)
           {
               myDymoPrinters = new DymoPrinters();
               myDymoPrinters.Initialize();
               foreach (IPrinter item in myDymoPrinters.DymoPrinterList)
               {
                   LabelWriterCmb.Items.Add(item.Name);
               }
               if (LabelWriterCmb.Items.Count > 0)
               {
                   LabelWriterCmb.SelectedIndex = 0;
               }
               else
               {
                   MessageBox.Show("Geen Dymo labelwriter gevonden");
                   Close();
                   return;
               }
    }
           private async void PrintLabelBtn_Click1(object sender, EventArgs e, ComboBox 						    labelWriterCmb)
           {
                    string tmpLabelXML = myDymoPrinters.LoadLabelXml(Path.Combine(Environment.GetFolderPath(
                                                Environment.SpecialFolder.LocalApplicationData), "LoginPC\\Voorraadbeheer\\product.label"));
    string  tmpLabel = myDymoPrinters.MakeLabelFromXml(xmlstring);
                    var tmp1  = await myDymoPrinters.GetRemainingLabels(labelWriterCmb.Text);
      if (tmp1 != null)
      {
          remaining.Text = tmp1.ToString();
      
      
          myDymoPrinters.PrintLabel(tmpLabel, labelWriterCmb.Text, aantal);
          var tmpi = await DymoPrinter.Instance.GetRollStatusInPrinter(labelWriterCmb.Text);
          rollstatus = string.Empty;
          labelsremaining = 0;
          labelname = string.Empty    ;
          if (tmpi != null)
          {
              rollstatus = tmpi.RollStatus.ToString();
              labelsremaining = Convert.ToInt32(tmpi.LabelsRemaining);
              labelname = tmpi.Name;
              
              if (labelsremaining < 6)
              {
                  remaining.ForeColor = Color.Red;
              }
              Labelstatus.Text = rollstatus;
              LabelNaam.Text = labelname;
              remaining.Text = labelsremaining.ToString();
          }
      }
    
    0 comments No comments