Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的代码使用VB语法,但不使用C#语法_C#_Vb.net - Fatal编程技术网

我的代码使用VB语法,但不使用C#语法

我的代码使用VB语法,但不使用C#语法,c#,vb.net,C#,Vb.net,在我的vb.net中,我有以下代码: Private WithEvents RF As SiritController2._0.RFIDController Public Sub StartReaders() RF = New SiritController2._0.RFIDController(HP.RfIdAddress, HP.RfIdUserName, HP.RfIdPassword, HP.RfIdAntena) EndSub private RFIDController

在我的vb.net中,我有以下代码:

Private WithEvents RF As SiritController2._0.RFIDController

Public Sub StartReaders()
    RF = New SiritController2._0.RFIDController(HP.RfIdAddress, HP.RfIdUserName, HP.RfIdPassword, HP.RfIdAntena)
EndSub
private RFIDController reader;

private void Start()
{
    reader = new RFIDController(HP.RfIdAddress, "HP.RfIdUserName", "HP.RfIdPassword", HP.RfIdAntena);
    reader.DetectRFID += Reader_DetectRFID;
}
在我的c中,我有以下代码:

Private WithEvents RF As SiritController2._0.RFIDController

Public Sub StartReaders()
    RF = New SiritController2._0.RFIDController(HP.RfIdAddress, HP.RfIdUserName, HP.RfIdPassword, HP.RfIdAntena)
EndSub
private RFIDController reader;

private void Start()
{
    reader = new RFIDController(HP.RfIdAddress, "HP.RfIdUserName", "HP.RfIdPassword", HP.RfIdAntena);
    reader.DetectRFID += Reader_DetectRFID;
}
这两个代码在同一个构造函数上调用同一个类

public RFIDController(string HostIP, string userName, string userPass, string AntennaNoPort = "1")
{
  RFIDController.__ENCAddToList((object) this);
  this.SvcTimerInterval = 45000;
  this.ReaderTimeOut = 1000;
  this.RaiseEventDelay = 0;
  this._lastReadRFTagNumber = string.Empty;
  this._LRRFT = new RFIDController.LastReadRFTagNumber();
  try
  {
    if (string.IsNullOrEmpty(userName) | string.IsNullOrEmpty(userPass))
      throw new Exception("Reader username or password cannot be empty.");
    this.IPAddress = HostIP;
    this.ReaderUser = userName;
    this.ReaderPW = userPass;
    this.AntennaNo = AntennaNoPort;
    this.Connect();
  }
  catch (Exception ex)
  {
    ProjectData.SetProjectError(ex);
    throw new Exception("Error occured while instantiating controller : " + ex.InnerException.ToString());
  }
}
为什么我会犯错误

“对象引用未设置为实例”

在我的C#代码中,而不是在我的VB代码中?一经检查,我就可以把我的护照填好。 我真的需要你的帮助

reader = new RFIDController(HP.RfIdAddress, "HP.RfIdUserName", "HP.RfIdPassword", HP.RfIdAntena);
应该是:

reader = new RFIDController(HP.RfIdAddress, HR.RfIdUserName, HP.RfIdPassword, HP.RfIdAntena);
也不是每个异常都有一个InnerException。因此,这可能会导致NullReferenceException,从而在catch块调用时隐藏真正的错误:

ex.InnerException.ToString()

哪一行抛出了“对象引用未设置为实例”错误?我打赌:在C程序中,HP实际上是D̶e̶l̶l̶null…@Jake在类methid中,即called@elgonzo不,不是。即使我使用实际的字符串本身,我仍然会得到一个合理的错误。如果将对象/道具本身作为字符串传递,
“HP.RfIdUserName”、“HP.RfIdPassword”
,请删除引号
,这可能是一个问题。