运行设备控制程序报错 CA1303和CA2101

wxf54318 2020-07-20 01:40:58
报错信息:
错误 CA1303 方法“bool Program.Checks(int _rc, byte _ReType)”将文本字符串作为“void Console.WriteLine(string value)”的调用的参数“value”进行传递。改为从资源表检索以下字符串:“Negative response”。

错误 CA2101 指定对 P/Invoke 字符串参数进行封送处理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Timers;
using System.Threading;

namespace CardDispenser
{
unsafe static class Program
{
private static bool Checks(int _rc, byte _ReType)
{
bool checksResult;
checksResult = false;
if (_rc == 0)
{
if (_ReType == 0x50)
{
Console.WriteLine("Positive response");
checksResult = true;

}
if (_ReType == 0x4e)
{
Console.WriteLine("Negative response");
// Command sending failed or command execution failed
//Console.WriteLine(ResErrMsg(St1, St2));
}
}
else
{
Console.WriteLine("Communication error");
}
return checksResult;
}


[DllImport("AAA.dll", CharSet = CharSet.Ansi)]
private static extern int CommClose(IntPtr ComHandle);

static void Main()
{

...
}
}
}
...全文
9230 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
github_36000833 2020-07-21
  • 打赏
  • 举报
回复
CA1303和CA2101是编译警告。可能你在项目编译设置,把‘警告’做为‘错误’处理了。 这两个警告都比较无害,可以选择忽视。 https://docs.microsoft.com/zh-cn/visualstudio/code-quality/ca1303 https://docs.microsoft.com/zh-cn/visualstudio/code-quality/ca2101

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧