Persian Calendar not valid with CultureInfo
Asked Answered
T

2

9

What's wrong with this code?

Error(Exception) message :

Not a valid calendar for the given culture.

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fa-Ir"); //Error
ci.DateTimeFormat.Calendar = new System.Globalization.PersianCalendar();
Application.CurrentCulture = ci;

And what's its solution?
Can I add a Calendar type to Windows XP regional option?

Tripping answered 27/3, 2011 at 12:3 Comment(1)
There is some information about the problems with Persian calendar in MSDN (see bottom of the page). Maybe it can help a little.Fanning
L
5

a dirty reflection-based workaround is here :

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4768d48e-aa04-4c15-b688-a58fa4373bc9/

Lianaliane answered 29/5, 2011 at 1:18 Comment(0)
C
3

It is explicitly mentioned in the MSDN article for PersianCalendar

Your application should not use a PersianCalendar object as the default calendar for a culture. The default calendar is specified by the CultureInfo.Calendar property and must be one of the calendars returned by the CultureInfo.OptionalCalendars property. Currently, the PersianCalendar class is not an optional calendar for any culture supported by the CultureInfo class and consequently cannot be a default calendar.

You cannot make this work. Use the Calendar as-is.

Cooks answered 27/3, 2011 at 12:13 Comment(5)
Is it possible to add a new culture type in Windows XP regional and Language options in control Panel?Tripping
No, you cannot fix this no matter what you try.Cooks
So,Is there any solution that help me to use VS controls(such as datetimepicker) with persian calendar in my application projects?Tripping
That's a completely different question. Start a new one.Cooks
if i add persian calendar in regional option i guess i can use it for this purpose, so it's the same question. but i will start new one:)Tripping

© 2022 - 2024 — McMap. All rights reserved.