'的TypeConverter'不包含' IsValid'的定义在MVC6中

时间:2015-09-22 10:51:21

标签: visual-studio-2005 asp.net-core-mvc

我正在使用MVC 6,并且我引用了以下名称空间,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Syncfusion.JavaScript.Shared.Serializer;
using System.Reflection;

这是我的代码,

static bool CanConvertTo<T>(string s)  {
   TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
   return converter.IsValid(s);
}

它抛出这样的错误,

&#39;的TypeConverter&#39;不包含&#39; IsValid&#39;的定义没有延伸方法&#39; IsValid&#39;接受类型&#39; TypeConverter&#39;的第一个参数。可以找到(你错过了使用指令或程序集引用吗?)

这只在MVC6中重现

如何解决此问题,还有其他解决办法吗?

Project.JSON

1 个答案:

答案 0 :(得分:0)

IsValid中有System, Version=4.0.0.0方法:

namespace System.ComponentModel
{
    public class TypeConverter
    {
        // other members

        public bool IsValid(object value)
        {
            // some implementation
        }
    }
}

您的配置中有两个框架:dnx451dnxcore50。我不确定IsValid中存在方法dnxcore50

如果您只使用dnx451框架,我建议您尝试一下:

1)将项目框架切换到dnx451(或从dnxcore50删除project.json部分。如果它没用,那么:

2)将项目更新为MVC 6 beta 7并使用project.jso中的下一个配置:

"dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "EntityFramework.Commands": "7.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
  },

  "frameworks": {
    "dnx451": { }
  }

我在具有此配置的项目中尝试了您的示例代码,并且没有任何问题。我的解决方案DNX SDK版本为1.0.0-beta7