Sau khi cài đặt Bản cập nhật kỷ niệm Windows 10 vào cuối tuần, bao gồm .NET Framework 4.6.2, một số mã đã ngừng hoạt động. Tôi đã quay lại phiên bản 1 tuần trước để đảm bảo rằng nó không liên quan đến mã của chúng tôi.Không gian tên System.Web.Globalization được giới thiệu với .NET 4.6.2 xung đột khi chạy với System.Globalization
Khi chạy, một lỗi được ném:
lỗi BC30561: 'Toàn cầu hoá' là mơ hồ, nhập khẩu từ các không gian tên hoặc 'System.Web, hệ thống' loại.
Stack trace:
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)
Đây là dòng vi phạm:
$.SetLanguage("<%= Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName %>");
Thay Globalization
với System.Globalization
sửa chữa được vấn đề, nhưng Visual Studio gợi ý rằng "tên có thể được đơn giản hóa", cho biết System
là không cần thiết.
Khi cài đặt một breakpoint tại dòng vi phạm, tôi có thể nhận được các lỗi tương tự thông qua các cửa sổ Immediate:
Globalization.CultureInfo.CurrentUICulture
error BC30560: 'CultureInfo' is ambiguous in the namespace 'System.Globalization'.
Nếu tôi hiểu đúng, có cả System.Globalization
và System.Web.Globalization
. Theo the API diff, một không gian tên mới đã được giới thiệu, có vẻ như đang gây ra vấn đề này.
+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; } + } +}
Tại sao lỗi này chỉ xuất hiện khi chạy? Làm thế nào tôi có thể làm cho nó không thành công tại thời gian biên dịch?
Dường như dòng vi phạm là mã nội tuyến trong trang aspx được biên dịch trong yêu cầu đầu tiên. Bạn có thể sử dụng aspnet_compiler.exe để biên dịch trước ứng dụng web của bạn và bạn sẽ thấy lỗi. – mattfei
Cùng một vấn đề tôi nhận được. Các mã đã được làm việc tốt nhưng sau khi cài đặt lại VS và tất cả những thứ khác, nó bắt đầu đưa ra lỗi tương tự. nhưng tôi nhận được sau khi instllation của Framework 4.5.2. Bạn đã tìm ra giải pháp chưa? – par
@par Giải pháp là hoàn toàn đủ điều kiện loại và bỏ qua Visual Studio khi nó nói tên có thể được đơn giản hóa.Tôi cho rằng đó cũng không phải là vấn đề nếu dự án của bạn nhắm mục tiêu 4.6.2 nhưng tôi chưa thử. – Stijn