I am using a third party COM component to communicate with hardware device in my .net 6 console application. Initially when I started implementing the functionality I was getting following error
Unable to cast COM object of type 'System.__ComObject' to interface type 'DrvFRLib.DrvFR'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A9BFA98D-04ED-4B1E-A874-4C6C3A91930E}' failed due to the following error: Unspecified error (0x80004005 (E_FAIL)).
and stack trace
at System.Runtime.CompilerServices.CastHelpers.ChkCastAny(Void* toTypeHnd, Object obj) at Gizmo.PointOfService.Devices.FiscalPrinters.FiscalPrinterDrivers.ShtrihFiscalPrinterDriver.d__5.MoveNext() in D:\My Documents\Visual Studio 2015\Projects\Gizmo\Gizmo.PointOfService\Gizmo.PointOfService\Devices\FiscalPrinters\FiscalPrinterDrivers\ShtrihFiscalPrinterDriver.cs:line 30 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Gizmo.PointOfService.Devices.FiscalPrinters.OFDFiscalPrinter.d__11.MoveNext() in D:\My Documents\Visual Studio 2015\Projects\Gizmo\Gizmo.PointOfService\Gizmo.PointOfService\Devices\FiscalPrinters\OFDFiscalPrinter.cs:line 101
After converting my application into a WPF app and basically hosting WPF app in my application like this
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
//run the app
await Program.Main(e.Args);
}
}
the error was gone and I was able to insatiate the COM component. Now the initial intention was to have my application running as windows service but once I tried to run the application as service the same exception would appear. Now I cant be sure but it looks like this COM component has some dependencies on GUI (WndProc) functionality ? So the question is whether anybody have experienced similar problems and perhaps have any ideas on potential workarounds?