A few days ago a strange error began to appear in the MonthCalendar component.

System.InvalidOperationException: Operation is not valid due to the current state of the object. at System.Windows.Forms.MonthCalendar.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

Windows 7 System, .Net Framework 4.0

The program has not changed for many years and worked fine, and suddenly began to fall when choosing a date in the calendar.

Has anyone come across this? Maybe Microsoft rolled out some kind of update that destroys the calendar?

Here a person seems to have a similar problem: Strange error in MonthCalendar just started happening out of nowhere

    1 answer 1

    The problem occurs when setting the BoldDates property to an array of dates instead of adding BoldDates one by one. Apparently, it appears after installing the update KB3023222.

     this.monthCalendar1.BoldedDates = new DateTime[] { new DateTime(2015, 04, 01), new DateTime(2015, 04, 02) }; 

    Hotfix .NET for this crash:

    https://support.microsoft.com/en-us/kb/3064711 (Offline)
    https://support.microsoft.com/en-us/kb/3064715 (Web)

    Problems solved:

    Assume that you are running a Windows Forms application. When the application is taken into account, it will be possible that the following is the case for the application .

    This bug on MS Connect: https://connect.microsoft.com/VisualStudio/feedback/details/1345128/errors-after-installing-kb3023222-update