首页 > 解决方案 > 需要帮助修复构建期间代码中的休息响应异常错误

问题描述

我得到了一些代码,开发人员告诉我,它们工作得很好。当我去运行调试时,代码不会生成并显示错误。我可以运行“以前”构建的代码。我不能做任何我必须放置需要“重建”的断点的事情

我和开发商谈过。我们进行了清理和重建解决方案,但它并没有解决问题。开发人员坚持认为代码在他的机器上运行良好,而这在我的机器上是个问题。我什至在另一台机器上尝试了代码并且遇到了同样的问题。

这是给我带来问题的代码:

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;
}

我在构建时收到以下错误: 在此处输入图像描述

由于开发人员表示此代码是正确的,我不知道如何构建它。

标签: c#

解决方案


使用Response?.error仅存在于 C# 6.0 及更高版本中的空条件运算符。

此外,表达式体成员仅存在于 C# 6.0 中,并在 7.0 中得到增强。确保您的 C# 版本至少为 7.0


推荐阅读