C# 新的PosExplorer()命令引发空引用异常

C# 新的PosExplorer()命令引发空引用异常,c#,C#,我正试图用C#打开Posiflex USB现金抽屉。这是代码(由其他人提供): 一旦执行到达代码: explorer=new PosExplorer(),将引发以下异常: mscorlib.dll中发生类型为“System.NullReferenceException”的未处理异常 如果有帮助,以下是堆栈跟踪: at Microsoft.PointOfService.Pos4NetTelemetry.IsCeipOptInEnabled() at System.Lazy`1.Create

我正试图用C#打开Posiflex USB现金抽屉。这是代码(由其他人提供):

一旦执行到达代码:

explorer=new PosExplorer(),将引发以下异常:

mscorlib.dll中发生类型为“System.NullReferenceException”的未处理异常

如果有帮助,以下是堆栈跟踪:

 at Microsoft.PointOfService.Pos4NetTelemetry.IsCeipOptInEnabled()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at Microsoft.PointOfService.Pos4NetTelemetry.get_Enabled()
   at Microsoft.PointOfService.Pos4NetTelemetry.SetCurrentProcessBitness()
   at Microsoft.PointOfService.PosExplorer.Initialize()
   at Microsoft.PointOfService.PosExplorer..ctor()
   at RunningRabbit.CashDrawerClass..ctor() in c:\C# Development\RunningRabbit\RunningRabbit\CashDrawerClass.cs:line 14
   at RunningRabbit.MainPOS.btnOpenDrawer_Click(Object sender, EventArgs e) in c:\C# Development\RunningRabbit\RunningRabbit\MainPOS.cs:line 261
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at RunningRabbit.Program.Main() in c:\C# Development\RunningRabbit\RunningRabbit\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

任何帮助都将不胜感激

您可以在堆栈跟踪中看到它:

 at Microsoft.PointOfService.Pos4NetTelemetry.IsCeipOptInEnabled()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at Microsoft.PointOfService.Pos4NetTelemetry.get_Enabled()
   at Microsoft.PointOfService.Pos4NetTelemetry.SetCurrentProcessBitness()
   at Microsoft.PointOfService.PosExplorer.Initialize()
   at Microsoft.PointOfService.PosExplorer..ctor()
   at RunningRabbit.CashDrawerClass..ctor() in c:\C# Development\RunningRabbit\RunningRabbit\CashDrawerClass.cs:line 14
   at RunningRabbit.MainPOS.btnOpenDrawer_Click(Object sender, EventArgs e) in c:\C# Development\RunningRabbit\RunningRabbit\MainPOS.cs:line 261
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at RunningRabbit.Program.Main() in c:\C# Development\RunningRabbit\RunningRabbit\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
PosExplorer在初始化时检查您是否允许它在安装POS for.NET期间向Microsoft发送遥测数据。 代码正在尝试读取此属性:

RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\POSfor.Net\\Setup").GetValue("CeipOptIn", (object) 0);
所以,如果您没有安装POS for.NET,则此子项不在您的注册表中,然后会引发异常

注:

遥测仅包含在.NET POS的1.14版本中。
我建议使用具有相同功能且无遥测功能的版本1.12

Soner,我一般理解空引用,但我无法理解为什么在这个特定实例中,我知道了错误。我们可以同时查看您的
PosExplorer
吗?PosExplorer是Microsoft.PointOfService的一部分library@PeterJ你知道为什么会这样吗?我也有同样的问题,但它只发生在一台特定的计算机上——代码在其他一些机器上工作。