George Hernando George Hernando - 3 years ago 243
C# Question

C# Error with Read Only assignment

I have a WPF C# project that I am moving to Visual Studio 2013.

The following code had compiled OK, but now it is failing:

CultureInfo origCulture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentCulture = new CultureInfo(DILData.GetString("Config_Locale"));

The following is declared:

using System.Globalization;

The error is:

Property or indexer 'System.Globalization.CultureInfo.CurrentCulture' cannot be assigned to -- it is read only

I did not have this problem before. What is it missing?

Answer Source

You are compiling the project against an old .NET Framework version. Try to set it to .NET 4.6 or higher.

In the .NET Framework 4.5.2 and earlier versions, the CurrentCulture property is read-only; that is, you can retrieve the property value, but you cannot set it. [..] Starting with the .NET Framework 4.6, the CurrentCulture property is read-write; you can both set and retrieve the property's value

Source: MSDN

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download