System.Globalization.CultureInfo不包含名称的定义 [英] System.Globalization.CultureInfo does not contain a definition for Name

查看:69
本文介绍了System.Globalization.CultureInfo不包含名称的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对System.Globalization.CultureInfo类和System.Globalization命名空间有这个特殊的问题.我正在从具有CultureInfo属性的API调用返回一个对象(语言).我能够在客户端成功地将其拉入 IENumerable< Language>语言{get;set;} ,但是当我尝试使用 var x = model.languages.First().AssociatedCulture.Name 这样的行进行构建时,遇到以下错误:

错误489'System.Globalization.CultureInfo'不包含'EnglishName'的定义,并且找不到扩展方法'EnglishName'接受类型为'System.Globalization.CultureInfo'的第一个参数(您是否缺少使用指令还是程序集引用?)

错误488在未引用的程序集中定义了类型'System.Globalization.CultureInfo'.您必须添加对程序集'System.Globalization,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用.

这是我尝试过的几行代码:

  var y = new CultureInfo("en");//作品var z = y.Name;//作品var x = model.languages.First().AssociatedCulture.EnglishName;//此行的错误. 

我不了解这个幻影错误.如果有帮助,则创建Language.cs的项目将使用.NET Portable v.4.5.

我尝试将其添加到web.config程序集块中,但没有骰子.

 <编译defaultLanguage ="c#" debug ="true" targetFramework ="4.5"><装配体>< add assembly ="System.Globalization,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"/>< add assembly ="System.Runtime,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"/>< add assembly ="System.Web.Abstractions,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>< add assembly ="System.Web.Routing,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>< add assembly ="System.Data.Linq,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = B77A5C561934E089"/>< add assembly ="System.Web.Helpers,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>< add assembly ="System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>< add assembly ="System.Web.WebPages,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>< add assembly ="System.Web.Abstractions,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"/>< add assembly ="System.Web.Routing,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"/>< add assembly ="System.Web.Mvc,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"/></程序集>< buildProviders>< add extension =.cshtml" type ="System.Web.WebPages.Razor.RazorBuildProvider,System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/></buildProviders></compilation> 

有人曾经遇到过这个问题吗?是由.NET Portable引起的吗?

解决方案

您需要项目引用 System.Globalization .

在编辑 web.config 文件时,您将添加从 .aspx / .cshtml 文件,这与您的项目引用(这些引用是您的项目的输出DLL的引用)是分开的且不同的.

通过解决方案资源管理器在Visual Studio中添加项目引用.

I have this peculiar issue with the System.Globalization.CultureInfo class and the System.Globalization namespace. I'm returning an object (Languages) from an API call that has a CultureInfo property. I'm able to successfully pull this on the client side into an IENumerable<Language> languages {get; set;} but when I try to build with a line such as var x = model.languages.First().AssociatedCulture.Name I'm met with the following errors:

Error 489 'System.Globalization.CultureInfo' does not contain a definition for 'EnglishName' and no extension method 'EnglishName' accepting a first argument of type 'System.Globalization.CultureInfo' could be found (are you missing a using directive or an assembly reference?)

Error 488 The type 'System.Globalization.CultureInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Here is the sequence of lines I have run to try this out:

var y = new CultureInfo("en"); //works
var z = y.Name; //works
var x = model.languages.First().AssociatedCulture.EnglishName; //error at this line.

I don't understand this phantom error. If it helps, the project that creates Language.cs uses the .NET portable v.4.5.

I have tried adding this to the web.config assemblies block but no dice.

<compilation defaultLanguage="c#" debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Globalization , Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
      <buildProviders>
        <add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </buildProviders>
    </compilation>

Has anyone experienced this issue before? Is it somehow caused by .NET portable?

解决方案

You need a project reference to System.Globalization.

When you edit the web.config file you're adding a reference for the dynamic assembly that's generated from your .aspx/.cshtml files, this is separate and distinct from your project references (which are references for the output DLL from your project).

Add a Project Reference in Visual Studio via Solution Explorer.

这篇关于System.Globalization.CultureInfo不包含名称的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆