首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >新的PosExplorer()命令抛出空引用异常

新的PosExplorer()命令抛出空引用异常
EN

Stack Overflow用户
提问于 2015-09-03 12:08:08
回答 1查看 2.1K关注 0票数 5

我试图打开一个带有C#的Posiflex现金抽屉。这是代码(由其他人提供):

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using Microsoft.PointOfService;

namespace MyNamespace
{
  public class CashDrawerClass
  {
    CashDrawer myCashDrawer;
    PosExplorer explorer;

    public CashDrawerClass()
    {
        explorer = new PosExplorer();
        DeviceInfo ObjDevicesInfo = explorer.GetDevice("CashDrawer", "RR-Drawer");
        myCashDrawer = explorer.CreateInstance(ObjDevicesInfo) as CashDrawer;
    }

    public void OpenCashDrawer()
    {
        myCashDrawer.Open();
        myCashDrawer.Claim(1000);
        myCashDrawer.DeviceEnabled = true;
        myCashDrawer.OpenDrawer();
        myCashDrawer.DeviceEnabled = false;
        myCashDrawer.Release();
        myCashDrawer.Close();
    }
  }
}

一旦执行到达代码:

资源管理器=新的PosExplorer(),将引发以下异常:

System.NullReferenceException类型的未处理异常发生在mscorlib.dll中。

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

代码语言:javascript
复制
 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()

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2016-10-14 14:15:41

在堆栈跟踪中可以看到:

初始化时的PosExplorer检查是否允许它在POS分期付款期间将遥测发送给微软用于.NET。代码试图读取此属性:

代码语言:javascript
复制
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\POSfor.Net\\Setup").GetValue("CeipOptIn", (object) 0);

因此,如果没有安装.NET的POS,则此Subkey不在注册表中,然后抛出异常。

注意:

遥测只包含在1.14版本的POS为.NET。我建议使用1.12版本的,它具有相同的功能,无需遥测。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32375213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档