dymosoftware / DCD-SDK-Sample

DYMO Connect SDK Samples
Other
60 stars 27 forks source link

Could not load file or assembly 'DYMOPrinting_x64' or one of its dependencies. An attempt was made to load a program with an incorrect format #22

Open githubsamurai opened 3 years ago

githubsamurai commented 3 years ago

All of my projects are the same... .NET Framework 4.7.2. All of them are set to Any CPU and Prefer 32bit is off. I have a winforms app that the SDK works fine on but when i installed the SDK in a ClassLibrary i get this error. I'm also attaching a screenshot if it helps.

Thanks! 2021-01-09_11-32-53

Dev-MRob commented 3 years ago

Having same issue

victornamuso commented 3 years ago

@githubsamurai @Dev-MRob any resolution? @dymosoftware would really love to make this work. Having to dump info off to a windows service from the web application to get this to work now.

dymosoftware commented 2 years ago

Hi, sorry for late response. Please try with latest version of SDK.

victornamuso commented 2 years ago

@dymosoftware

Here's what I'm getting with the new SDK and this very basic source code:

Source Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DymoSDK.Implementations;

namespace web_test.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            DymoSDK.App.Init();

            //var printers = DymoSDK.Implementations.DymoPrinter.Instance.GetPrinters();

            DymoPrinter.Instance.GetPrinters();

            return View();
        }
    }
}

Error

System.Exception
  HResult=0x80131500
  Message=Error getting printers
  Source=DymoSDK
  StackTrace:
   at DymoSDK.Implementations.DymoPrinter.GetPrinters()
   at web_test.Controllers.HomeController.Index() in e:\projects\test-console\web-test\Controllers\HomeController.cs:line 23
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
NullReferenceException: Object reference not set to an instance of an object.
jfquarto commented 2 years ago

I am having the same issue. Did you find a solution ?

skillsinc-Ed commented 2 years ago

I found that I had to set the compile to Target CPU: x86 instead of Any CPU and then it worked for me, but I don't remember if that was the same error I was getting, I just know I could only get it to work with x86.

victornamuso commented 2 years ago

I did the same as @skillsinc-Ed as a stop gap. Our solution initially works but then the DYMO dll crashes the spooler at what seems to be random points. Makes the solution unreliable. I'm planning on giving them a call next week.

jfquarto commented 2 years ago

In a WPF application I load my labelprinter dll dynamically (via System.Reflection.Assembly.CreateInstance and AppDomain.CurrentDomain.AssemblyResolve). In my labelprinter dll I have references to the required DYMO.Connect and SkiaSharp packages. This dll and all the referenced ones are situated in a submap in the WPF application's bin map. I have this dll loading technique working for several other 3rd party software components. Now when I run my application this way I get the "Error getting printers" exception on calling the DymoSDK.Implementations.DymoPrinter.GetPrinters().

As a sorta workaround I found that adding a "probing" element to the app.config of the WPF application "solved" the issue:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
  <!-- Discover assemblies in /lib -->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
</configuration>