类型或名称空间" RestSharp"和"系统"无法找到

时间:2016-01-12 07:28:57

标签: c# asp.net asp.net-mvc asp.net-core-mvc

在project.cs文件中添加以下代码

"frameworks": {
    "net451": {
      "dependencies": {
        "RestSharp": "105.2.3"
      },
      "frameworkAssemblies": {
        "System.configuration": "4.0.0.0"
      }
    },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  },

下面是显示程序集和引用被添加到引用文件夹的图像。当我构建解决方案时,我收到并且错误为" 类型或命名空间名称'配置&#39 ;命名空间中不存在'系统' "和" 类型或命名空间名称' RestSharp'无法找到"

enter image description here

以下是代码。

using System.Collections.Generic;
using CommonModels;
using RestSharp;
using ServiceLayer.Interface;
using  System;



namespace ServiceLayer.ImplementaionClass
{
    public class WebApiCall<T> : IWebApiCall<T> where T : class 
    {
        private readonly string _baseUrl = string.Empty;
        public WebApiCall()
        {
            _baseUrl = System.Configuration.ConfigurationManager.AppSettings["ApiBaseUrl"];
        }

    public GenericResponseObject<T> GetResponseObject(string actionurl,params KeyValuePair<string, string>[] namePairs)
        {
            RestClient restClient = new RestClient(_baseUrl);
            RestRequest restRequest = new RestRequest(actionurl, Method.GET);
            foreach (KeyValuePair<string, string> items in namePairs)
            {
                restRequest.AddParameter(items.Key, items.Value);
            }
            IRestResponse<GenericResponseObject<T>> response = restClient.Execute<GenericResponseObject<T>>(restRequest);
            GenericResponseObject<T> responseObject = response.Data;
            return responseObject;
        }


    }
}

2 个答案:

答案 0 :(得分:1)

通过从project.json文件中删除以下代码

解决了该问题
"dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }

参考解决方案http://forums.asp.net/t/2060969.aspx?The+type+or+namespace+name+Configuration+does+not+exist+in+the+namespace+System+

答案 1 :(得分:0)

测试您的项目属性,看看您是否使用紧凑框架? 问题似乎是项目配置而不是代码本身。 改变你的目标框架,看看会发生什么。