Unable to change calendar exception days in microsoft project

This is my code which adding production calendars

public static void AddProductionCalendar(this Project project, List<ProductionCalendarDto> productionCalendars)
    {
        project.Calendar = null;

        var calendarsToDelete = project.Calendars.ToList() ?? new List<Calendar>();
   
        foreach(var calendar in calendarsToDelete)
        {
            project.Calendars.Remove(calendar);
        }

        foreach (var productionCalendar in productionCalendars)
        {
            try
            {
                var cal = project.Calendars.Add(productionCalendar.Name);
                cal.Uid = productionCalendar.Id;

                if (productionCalendar.IsDefault)
                {
                    project.Set(Prj.Calendar, cal);
                    project.Calendar = cal;
                }

                cal.Exceptions.AddRange(productionCalendar.Calendars
                    .Select(c =>
                    {
                        var clException = new CalendarException();

                        clException.Name = c.Name;
                        clException.ToDate = c.ToDate;
                        clException.FromDate = c.FromDate;

                        if(c.IsDayWorking)
                        {
                            clException.DayWorking = c.IsDayWorking;
                            clException.WorkingTimes.Add(new WorkingTime(DateTime.ParseExact("0001-01-01T09:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), DateTime.ParseExact("0001-01-01T13:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)));
                            clException.WorkingTimes.Add(new WorkingTime(DateTime.ParseExact("0001-01-01T14:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture), DateTime.ParseExact("0001-01-01T18:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)));
                        }

                        return clException;
                    }));


                foreach (var weekDay in productionCalendar.WeekDays)
                {
                    var newWorkingTimes = weekDay.WorkingTimes
                        .Select(w => new WorkingTime(w.From, w.To));

                    var weekDays = new WeekDay(weekDay.DayType, newWorkingTimes)
                    {
                        DayWorking = weekDay.DayWorking,
                    };
                    cal.WeekDays.Add(weekDays);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Ошибка во время создания производственного календаря {productionCalendar.Name}: {ex.Message}");
            }
        }
    }

Example of ProductionCalendarDto in json

  {
"id": 1,
"name": "Импортированный производственный календарь: 2023-05-04",
"calendars": [
  {
    "name": "День народного единства",
    "fromDate": "2030-11-04T00:00:00",
    "toDate": "2030-11-04T23:59:00",
    "isDayWorking": false
  },
  {
    "name": "Новогодние каникулы",
    "fromDate": "2014-01-01T00:00:00",
    "toDate": "2014-01-01T23:59:00",
    "isDayWorking": false
  }
],
"weekDays": [
  {
    "dayType": 7,
    "workingTimes": []
  },
  {
    "dayType": 1,
    "workingTimes": []
  },
  {
    "dayType": 2,
    "workingTimes": [
      {
        "to": "0001-01-01T13:00:00",
        "from": "0001-01-01T09:00:00"
      },
      {
        "to": "0001-01-01T18:00:00",
        "from": "0001-01-01T14:00:00"
      }
    ],
    "dayWorking": true
  },
  {
    "dayType": 3,
    "workingTimes": [
      {
        "to": "0001-01-01T13:00:00",
        "from": "0001-01-01T09:00:00"
      },
      {
        "to": "0001-01-01T18:00:00",
        "from": "0001-01-01T14:00:00"
      }
    ],
    "dayWorking": true
  },
  {
    "dayType": 4,
    "workingTimes": [
      {
        "to": "0001-01-01T13:00:00",
        "from": "0001-01-01T09:00:00"
      },
      {
        "to": "0001-01-01T18:00:00",
        "from": "0001-01-01T14:00:00"
      }
    ],
    "dayWorking": true
  },
  {
    "dayType": 5,
    "workingTimes": [
      {
        "to": "0001-01-01T13:00:00",
        "from": "0001-01-01T09:00:00"
      },
      {
        "to": "0001-01-01T18:00:00",
        "from": "0001-01-01T14:00:00"
      }
    ],
    "dayWorking": true
  },
  {
    "dayType": 6,
    "workingTimes": [
      {
        "to": "0001-01-01T13:00:00",
        "from": "0001-01-01T09:00:00"
      },
      {
        "to": "0001-01-01T18:00:00",
        "from": "0001-01-01T14:00:00"
      }
    ],
    "dayWorking": true
  }
],
"isDefault": true

}

When I save mpp file after that I cant change any data in calendar when I open that file in Microsoft Project. I pin screenshot of it.

Screenshot_157.png (31.6 KB)

@Vardan21,
I’ve tried to use your code on new Project(), but cannot observe the behavior you’ve described (had to skip “Standard” calendar during removal of calendars because it cannot be removed).
Could you attach source .mpp file which I can use to reproduce the issue?

This is my .mpp file which is broken

Календарный_план_проект_MOY 1.zip (374.9 KB)

Sorry for disinformation. I figured out that this problem not related with this method, because I delete it and no matter what problem is still there. Can you inspect my broken mpp file which I send you and tell me why this happening?

@Vardan21,
could you also attach source .mpp file?

What do you mean source .mpp file? We can speak in russian if you want.

@Vardan21,

I mean .mpp file before modification (before it’s gets broken).

The language of this forum is English and other English-speaking people with the similar issue may want to read the solution, so it’s better to use English.

This is my template file. Based on it I make file. From python I get all information(tasks, predcessors, e.t.c) which I use to create it template.zip (78.3 KB)

@Vardan21,

I’ve reproduced the issue by simply opening and saving template.mpp using Aspose.Tasks.

I have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): TASKSNET-10913

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as TASKSNET-10913) have been fixed in this update.