DCD-SDK-Sample icon indicating copy to clipboard operation
DCD-SDK-Sample copied to clipboard

System.NullReferenceException when calling

Open PerryCodes opened this issue 4 years ago • 10 comments

System.NullReferenceException: 'Object reference not set to an instance of an object.' is received whenever I call: DymoSDK.App.Init();

I'm using the WPF sample here. Attempting this with "DCDSetup1.4.2.82.exe" installed (DYMO Connect for Desktop v1.4.2.82).

From reading through other issues, it seems like once you've got this framework working, if you change a single version of ANYTHING... it will break.

Does anyone have anything good to say about this mess?

PerryCodes avatar Oct 17 '21 16:10 PerryCodes

Hello!

Yes, SkiaSharp version is important!

First things first, make sure the following NuGet packages installed (versions too!): DYMO.Connect.SDK (last version) SkiaShap (1.68.0) SkiaSharp.View (1.68.0)

It should work this way. Also for me, I have a "Print" service is a separated project, that's the only one using this packages. Using DryIoc container, calling a method from that service in a different project is only possible if I copy all SkiaShap..blabla...dll (3 or 4) files into that project's output folder. (It's only copying the SkiaSharp.dll and Dymo dll when I'm building the solution)

Hope this helps!

buruhazard avatar Jan 14 '22 07:01 buruhazard

I have the same problem. I have checked all versions and everything seems to be correct, but unfortunately it does not work.

Hawk1401 avatar Feb 02 '22 19:02 Hawk1401

After you call DymoSDK.App.Init(); YOU MUST CALL DymoPrinter.Instance.GetPrinters(); at least once! Just by itself, or you can create a list for later use. That was the issue for me in one point.

buruhazard avatar Feb 03 '22 02:02 buruhazard

After a move of despair, I comment out the line DymoSDK.App.Init() and it worked.

Panagiotis-Sklidas avatar May 06 '22 07:05 Panagiotis-Sklidas

DymoSDK.App.Init() appears to always fails with a null exception when running inside the Visual Studio debugger. This applies to both the WPF and VB sample. If you launch the application outside of Visual Studio it should work fine.

sceBruce avatar Jul 31 '22 21:07 sceBruce

I'm seeing the same NullException error on the App.Init() line. I downgraded thr SkiaSharp packages to 1.68 but it had no effect.

If I comment the line out, as it was suggested by @Panagiotis-Sklidas above, I get a KeyNotFoundException when trying to load the label file.

Also, as suggested by @sceBruce , if I run the compiled app outside of Visual Studio, or if I change the configuration to "Release" (so it doesn't use the Debugger), I get a ReflectionTypeLoadException on the next line after Init, when it tries to retrieve DymoLabel.Instance.

Does anyone have a WORKING, sample .NET app?

mklopez avatar Aug 01 '22 19:08 mklopez

The VB sample is a Console application. Run the compiled application outside of Visual Studio. Console applications must be run with Administrator privilege. Launch the .exe with Run As Administrator.

sceBruce avatar Aug 01 '22 19:08 sceBruce

I understand that the sample is a console app, and I ran it from an administrator-level command line.

After a lot of trial and error, I managed to run the sample successfully only after doing this:

  • Restoring all the nuget package dependencies.
  • Updating all the packages (Using Visual Studio's Package Manager) to their latest versions.
  • Downgrading the package SkiaShat.Views to version 1.68
  • Compiling the app, and then running VB_DYMOSDK_Sample.exe from a command line, outside of Visual Studio

Not being able to use the VS debugger with the SDK is a HUGE issue. It would be great if the developers could offer an alternative, or fix the issue in the Init() function.

mklopez avatar Aug 01 '22 19:08 mklopez

To anyone still having this issue, try VS 2019. This error seems to be associated with VS 2022. Hopefully it gets addressed in the future.

knight-dev avatar Apr 04 '23 09:04 knight-dev

I may have found a solution.

If your exception settings in Visual Studio are not the same as the default settings then take note of Visual Studio's exception settings on your computer before proceeding. Then resetting the exception settings back to default seemed to work for me. After you reset, restore your settings that aren't default by manually adding them.

I hope this works for everyone else having the same problem.

ipacheco-formalloy avatar Aug 10 '23 22:08 ipacheco-formalloy