c# - 需要帮助修复构建期间代码中的休息响应异常错误
问题描述
我得到了一些代码,开发人员告诉我,它们工作得很好。当我去运行调试时,代码不会生成并显示错误。我可以运行“以前”构建的代码。我不能做任何我必须放置需要“重建”的断点的事情
我和开发商谈过。我们进行了清理和重建解决方案,但它并没有解决问题。开发人员坚持认为代码在他的机器上运行良好,而这在我的机器上是个问题。我什至在另一台机器上尝试了代码并且遇到了同样的问题。
这是给我带来问题的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Sample.JSONDeserializers
{
public class RESTResponseException : Exception
{
public HttpStatusCode StatusCode { get; set; }
public RESTResponse Response
{
get; set;
}
public RESTError Error
{
get => Response?.error;
}
public RESTResponseException(RESTResponse data, HttpStatusCode statusCode)
{
Response = data;
StatusCode = statusCode;
}
public RESTResponseException(RESTResponse data, HttpStatusCode statusCode, string message)
: base(message)
{
Response = data;
StatusCode = statusCode;
}
public RESTResponseException(RESTResponse data, HttpStatusCode statusCode, string message, Exception inner)
: base(message, inner)
{
Response = data;
StatusCode = statusCode;
}
public override string ToString()
{
return $"REST Exception: {Response?.error?.message?.value} (Http Response {StatusCode}) | \n{base.ToString()}";
}
}
}
具体部分是:
public RESTError Error
{
get => Response?.error;
}
由于开发人员表示此代码是正确的,我不知道如何构建它。
解决方案
使用Response?.error
仅存在于 C# 6.0 及更高版本中的空条件运算符。
此外,表达式体成员仅存在于 C# 6.0 中,并在 7.0 中得到增强。确保您的 C# 版本至少为 7.0
推荐阅读
- c# - 如何在派生控制器中模拟 HttpContext.RequestServices.GetService<> 注入的服务?
- python - 任务算法
- sql - 如何找到两个值不同且其中一个可以为 NULL 的行?为什么 NULL != 1 是假的?
- tensorboard - TensorBoard 上只有黑色图像
- google-sheets - 将具有开始和结束日期的单个记录转换为 Google 表格中的多个记录?
- java - 使用 Optionals 对多个属性进行 Java 空检查
- css - 使用 CSS 移动标签元素(无 JS)
- ios - Xamarin iOS 错误 CS7027 使用文件中的公钥对输出进行签名时出错
- tensorflow - 将 tensorflow 2.0 估计器转换为 tensorflow lite
- python - 在单独的函数中使用相同的键值使用 python 解析 JSON 时出现键错误