microsoft / Dynamics365Commerce.Solutions

Repository for hosting the Dynamics 365 Commerce end to end sample solutions
Other
58 stars 26 forks source link

Issue loading HWS custom devices at runtime #58

Closed rphillipsnwt closed 1 year ago

rphillipsnwt commented 1 year ago

Hello,

I am trying to update my extensions to support release/9.42. I was able to update my code so that it builds just fine, but when I attempt to run it my custom HWS devices are not loading and the POS is throwing errors.

My initial test is focused on Store Commerce with a local/dedicated HWS.

POS-HWS-Local


Error 1) When the POS interacts with my payment device I receive the following error in the event viewer.

Hardware Station operation failed for request uri: 'http://localhost/PaymentTerminal/Lock' with controller '' and method ''.
 isExternalPeripheralFailure: 'True'.
 ExceptionMessage: 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Commerce.Runtime.RequestHandlerAdapter' to type 'Microsoft.Dynamics.Commerce.Runtime.Handlers.INamedRequestHandler'.
   at Microsoft.Dynamics.Commerce.HardwareStation.PeripheralLockManager.Resolve[TPeripheral](AcquireLockRequest lockRequest, Type requestType, ResolveSource& source)
   at Microsoft.Dynamics.Commerce.HardwareStation.PeripheralLockManager.AcquireLock[TRequest,TPeripheral](AcquireLockRequest request)
   at Microsoft.Dynamics.Commerce.HardwareStation.Peripherals.PaymentTerminal.PaymentDeviceWrapper.LockDevice(LockPaymentTerminalDeviceRequest request)
   at Microsoft.Dynamics.Commerce.HardwareStation.Peripherals.PaymentTerminal.PaymentDeviceWrapper.Execute(Request request)
   at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.<ExecuteCore>d__53`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.<ExecuteCore>d__53`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.<Execute>d__52`1.MoveNext()
...

The documentation still does not reference INamedRequestHandlerAsync and the example code disables the compiler error with pragmas.

Should I be disabling the error as well and build to target the non-async INamedRequestHandler? In release/9.41 I did not update INamedRequestHandler to INamedRequestHandlerAsync, ignoring the warning, because I encountered the same issues that I am encountering now. My customizations worked correctly for release/9.41.


Error 2) When the POS interacts with my custom device I receive the following error in the event viewer. Possibly this is merely related to error 1.

Hardware Station operation failed for request uri: 'http://localhost/MyCustomDevice/MyCustomMethod' with controller '' and method ''.
 isExternalPeripheralFailure: 'False'.
 ExceptionMessage: 'System.InvalidOperationException: Composition does not have any instances of IHardwareStationController corresponding to the controller 'MyCustomDevice'
   at Microsoft.Dynamics.Commerce.HardwareStation.HardwareStationControllerSelector.GetControllerComponent(String controllerName, String methodName)
   at Microsoft.Dynamics.Commerce.HardwareStation.HardwareStationControllerSelector.SelectController(HttpRequestMessage request)
   at System.Web.Http.Tracing.Tracers.HttpControllerSelectorTracer.<>c__DisplayClass6_0.<System.Web.Http.Dispatcher.IHttpControllerSelector.SelectController>b__1()
   at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
   at System.Web.Http.Tracing.Tracers.HttpControllerSelectorTracer.System.Web.Http.Dispatcher.IHttpControllerSelector.SelectController(HttpRequestMessage request)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__17`1.MoveNext()
...

The documentation references IController, not IHardwareStationController. But it also is mentioning the Retail SDK, not the Commerce SDK, so it is obviously dated. Regardless, the example code also references IController, so maybe "IHardwareStationController" is a rabbit trail and fixing error 1 will address this issue as well.

rphillipsnwt commented 1 year ago

Error 2 can be ignored, it is unrelated to error 1.

thdigia commented 1 year ago

@rphillipsnwt Did you find a solution to this? We bumped into this while upgrading our payment connectors from 9.39 to 9.42.

rphillipsnwt commented 1 year ago

@thdigia Use the "#pragma" directives like on lines 56 and 58 in the sample and keep it a INamedRequestHandler (non-async).

I don't know why they were so hasty to switch the async warning in .41 to an error in .42, but the approach for now seems to be to ignore the error.

LordDorn commented 1 year ago

It turned out to solve a similar problem as follows: in the properties of the problematic assembly project, I changed the Target Framework from net.standart2.0 to .Net Framework 4.7.2 and the build is working, there is no error anymore.: "Composition does not have any instances of IHardwareStationController corresponding to the controller 'MyCustomCuntroller"