dymosoftware / DCD-SDK-Sample

DYMO Connect SDK Samples
Other
60 stars 27 forks source link

Not working in Excel VSTO Add-in #21

Open gjnijenhuis opened 3 years ago

gjnijenhuis commented 3 years ago

I can't get the package working in our Excel VSTO Add-in application.

Visual Studio 2019 DCD 1.3.2.14 Dymo.Connect.SDK 1.3.1.115

To debug it I created a simple application using the Excel VSTO Add-in template, just for this test.

ThisAddin.cs code:

using DymoSDK.Implementations;

namespace DymoTestExcel
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            var printers = DymoPrinter.Instance.GetPrinters();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

No printers are found. Count of printers remains 0.

I also upgraded to the latest beta: Dymo.Connect.SDK 1.3.1.160-beta

Code was modified to add the init method:

using DymoSDK.Implementations;

namespace DymoTestExcel
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            DymoSDK.App.Init();
            var printers = DymoPrinter.Instance.GetPrinters();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

Now an exception is thrown on DymoSDK.App.Init(); :

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'file:///C:\Users\a1018409\AppData\Local\assembly\dl3\3GY0P7VE.C5K\GPQ1DZYA.M4K\0d2e407c\00055c8c_b223d601\x64\PrintingSupportLibrary.dll' or one of its dependencies. The system cannot find the file specified.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Everything is working fine when using a C# console app, so it must be related somehow to the deployment used by VSTO.