We are developing an Add-On using Business One Studio for Microsoft Visual Studio. We have added several System Forms into the solution using SAP Business One Installed Templates.
We have custom c# code that we execute at different events on these forms (this.DataAddBefore, this.DataUpdateAfter etc). We then create the .ard file with AddOnRegDataGen.exe and deploy the Add-On. All seems well, until we click the Preview icon on a marketing document.
Then our Add-On immediately crashes with the following SAP System Message:
This does not occur for any of the marketing documents that have not been added into our Add-On solution. We have double checked our code to be sure we're catching all exceptions. We have also used DebugDiag 2 to listen to the process while it crashes. That has given us two interesting exceptions:
Type: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Type: System.InvalidCastException
Message: Unable to cast COM object of type 'SAPbouiCOM.PrintEventInfoClass' to interface type 'SAPbouiCOM.IPrintEventInfo'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EF8A2329-3D49-4136-9DEB-F1CB1E27DC18}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Stack:
[GCFrame]
[GCFrame]
[HelperMethodFrame_PROTECTOBJ]
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
[DebuggerU2MCatchHandlerFrame]
[GCFrame]
[GCFrame]
and
Type: System.ArgumentException
Message: Object of type 'SAPbouiCOM.ReportDataInfoClass' cannot be converted to type 'SAPbouiCOM.PrintEventInfo&'.
Stack: [HelperMethodFrame]
System.RuntimeType.TryChangeType(System.Object, System.Reflection.Binder, System.Globalization.CultureInfo, Boolean)
System.Reflection.MethodBase.CheckArguments(System.Object[], System.Reflection.Binder, System.Reflection.BindingFlags, System.Globalization.CultureInfo, System.Signature)
System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
[DebuggerU2MCatchHandlerFrame]
[GCFrame]
[GCFrame]
We have tried building the Add-On for Any CPU as well as x86 but the error still occurs.
We are running SAP B1 9.00.059 PL: 7
Has anyone had this issue of the Print Layout crashing your Business One Studio Add-On?
Thank You!!