gpt4 book ai didi

asp.net - .NET 4.6.2 引入的 System.Web.Globalization 命名空间在运行时与 System.Globalization 发生冲突

转载 作者:行者123 更新时间:2023-12-02 05:35:50 25 4
gpt4 key购买 nike

周末安装 Windows 10 周年更新(其中包括 .NET Framework 4.6.2)后,一些代码停止工作。我已返回 1 周前的版本,以确保它与我们的代码无关。

运行时抛出错误:

error BC30561: 'Globalization' is ambiguous, imported from the namespaces or types 'System.Web, System'.

堆栈跟踪:

System.Web.HttpCompileException (0x80004005): C:\path\to\project\MasterPages\SiteMaster.master(71): error BC30561: 'Globalization' is ambiguous, imported from the namespaces or types 'System.Web, System'.
at System.Web.Compilation.BuildManager.PostProcessFoundBuildResult(BuildResult result, Boolean keyFromVPP, VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey, Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile)
at System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData)
at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)

这是有问题的行:

$.SetLanguage("<%= Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName %>");

Globalization 替换为 System.Globalization 可以解决问题,但 Visual Studio 建议“名称可以简化”,表明 System 是没有必要。

在有问题的行设置断点时,我可以通过立即窗口得到相同的错误:

Globalization.CultureInfo.CurrentUICulture
error BC30560: 'CultureInfo' is ambiguous in the namespace 'System.Globalization'.

如果我理解正确的话,有System.GlobalizationSystem.Web.Globalization。根据the API diff ,引入了一个新的命名空间,这似乎是导致此问题的原因。

+namespace System.Web.Globalization {
+ public interface IStringLocalizerProvider {
+ string GetLocalizedString(CultureInfo culture, string name, params object[] arguments);
+ }
+ public sealed class ResourceFileStringLocalizerProvider : IStringLocalizerProvider {
+ public const string ResourceFileName = "DataAnnotation.Localization";
+ public ResourceFileStringLocalizerProvider();
+ public string GetLocalizedString(CultureInfo culture, string name, params object[] arguments);
+ }
+ public static class StringLocalizerProviders {
+ public static IStringLocalizerProvider DataAnnotationStringLocalizerProvider { get; set; }
+ }
+}

为什么这个错误只在运行时出现?如何让它在编译时失败?

最佳答案

Bug Crusher 的答案是正确的。要解决 Stijn 对答案的评论,只需在您的项目中搜索“全局化”即可。并删除它的每个实例。我不会使用“查找+替换”来执行此操作,因为这可能会产生意想不到的副作用。

然后确保您编辑的每个文件顶部都有正确的导入或使用语句。

VB-导入 System.Globalization

C#-使用 System.Globalization;

这就是 VS 提出的修复方案。

关于asp.net - .NET 4.6.2 引入的 System.Web.Globalization 命名空间在运行时与 System.Globalization 发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38828248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com