dymosoftware / DCD-SDK-Sample

DYMO Connect SDK Samples
Other
60 stars 27 forks source link

System.NullReferenceException when calling #36

Open PerryCodes opened 2 years ago

PerryCodes commented 2 years ago

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?

buruhazard commented 2 years ago

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!

Hawk1401 commented 2 years ago

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

buruhazard commented 2 years ago

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.

Panagiotis-Sklidas commented 2 years ago

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

sceBruce commented 2 years ago

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.

mklopez commented 2 years ago

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?

sceBruce commented 2 years ago

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.

mklopez commented 2 years ago

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:

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.

knight-dev commented 1 year ago

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.

ipacheco-formalloy commented 1 year ago

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.