重新编译.dll时出错

本文关键字:dll 出错 编译 新编译 | 更新日期: 2023-09-27 18:22:44

当我尝试重建.dll 时,会出现以下错误

请告知我可以用什么来替换这些行,以便编译代码。

背景信息(可能不相关):

.dll是控制圣诞灯程序的外接程序输出模块的一部分。它将程序中的数据输出到选定的串行端口,告诉连接的继电器板哪些继电器要打开或关闭。我打算修改输出以适合我的设备,这样继电器1 2 3打开和4 5 6 7 8关闭的输出将不是FF FF FF 00 00 00 00,而是发送我所拥有的板的适当格式。(见下文)

http://www.tinyosshop.com/image/data/board_modules/usbrelay4-5.jpg

错误CS0571"SerialSetupDialog.SelectedPort.get":无法显式调用运算符或访问器

它引用了本节中的行:

private void buttonSerialSetup_Click(object sender, EventArgs e)
{
  SerialSetupDialog serialSetupDialog = new SerialSetupDialog(this.m_selectedPort);
  if (((Form) serialSetupDialog).ShowDialog() != DialogResult.OK)
    return;
  this.m_selectedPort = serialSetupDialog.get_SelectedPort();
}

还有3种情况:错误CS0221常量值"-128"无法转换为"字节"(使用"未检查"语法覆盖)

编译器不喜欢这部分代码。"(byte)sbyte.MinValue;"

private void Protocol1Event(byte[] channelValues)
{
  int length1 = channelValues.Length;
  int count = 2;
  int length2 = 2 + 2 * length1 + (2 + 2 * length1) / 100;
  if (this.m_p1Packet.Length < length2)
    this.m_p1Packet = new byte[length2];
  this.m_p1Packet[0] = (byte) 126;
  this.m_p1Packet[1] = (byte) sbyte.MinValue;
  this.m_threadPosition = 10;
  for (int index = 0; index < length1; ++index)
  {
    if ((int) channelValues[index] == 125)
    {
      this.m_threadPosition = 11;
      this.m_p1Packet[count++] = (byte) 124;
    }
    else if ((int) channelValues[index] == 126)
    {
      this.m_threadPosition = 12;
      this.m_p1Packet[count++] = (byte) 124;
    }
    else if ((int) channelValues[index] == (int) sbyte.MaxValue)
    {
      this.m_threadPosition = 13;
      this.m_p1Packet[count++] = (byte) sbyte.MinValue;
    }
    else
    {
      this.m_threadPosition = 14;
      this.m_p1Packet[count++] = channelValues[index];
    }
    if (count % 100 == 0)
    {
      this.m_threadPosition = 15;
      this.m_p1Packet[count++] = (byte) 125;
    }
    this.m_threadPosition = 16;
  }
  this.m_threadPosition = 17;
  if (this.m_running)
  {
    while (this.m_selectedPort.WriteBufferSize - this.m_selectedPort.BytesToWrite <= count)
      Thread.Sleep(10);
    this.m_threadPosition = 18;
    this.m_selectedPort.Write(this.m_p1Packet, 0, count);
    this.m_threadPosition = 19;
  }
  this.m_threadPosition = 20;
}
private void Protocol2Event(byte[] channelValues)
{
  byte num1 = (byte) sbyte.MinValue;
  int length = channelValues.Length;
  byte[] array = new byte[8];
  int num2 = 0;
  while (num2 < length)
  {
    int num3 = Math.Min(num2 + 7, length - 1);
    this.m_p2Packet[1] = num1++;
    if (num3 >= length - 1)
      this.m_p2Zeroes.CopyTo((Array) this.m_p2Packet, 3);
    Array.Clear((Array) array, 0, 8);
    for (int index = num2; index <= num3; ++index)
    {
      byte num4 = channelValues[index];
      byte num5 = num4;
      if ((int) num4 >= 1 && (int) num4 <= 8)
        array[(int) num4 - 1] = (byte) 1;
      else if ((int) num5 >= 1 && (int) num5 <= 8)
        array[(int) num5 - 1] = (byte) 1;
    }
    byte num6 = (byte) (1 + Array.IndexOf<byte>(array, (byte) 0));
    this.m_p2Packet[2] = num6;
    int index1 = num2;
    int count = 3;
    while (index1 <= num3)
    {
      this.m_p2Packet[count] = (byte) ((uint) channelValues[index1] - (uint) num6);
      ++index1;
      ++count;
    }
    if (this.m_running)
      this.m_selectedPort.Write(this.m_p2Packet, 0, count);
    num2 += 8;
  }
}

重新编译.dll时出错

(byte)sbyte.MinValue;抛出错误的原因是sbytes最小值为-128,而bytes最小值为0。因此,将其转换为另一个将导致溢出。如果你真的想要这种行为,你可以使用关键字unchecked如下:

byte b = unchecked((byte)sbyte.MinValue);

然而,这将使b的值为128。

为了回答你问题的另一部分,我认为替换:

serialSetupDialog.get_SelectedPort();

带有:

serialSetupDialog.SelectedPort;

应该解决这个问题。