ical.net: PRODID not being respected after upgrade from v2 to v4

Hi,

I just upgraded from v2 to v4. After getting the code to recompile and changing all the lower case values to upper case, I am left with one difference that is showing up in my unit tests.

The ProductId of the calendar isn’t being respected when serializing calendar events. I used to set the productId and serialize an event like this:

           var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//www.skycourt.ca//RemoteAPI/EN"
            };
            calendar.Events.Add(ev);
            var serializer = new CalendarSerializer(new SerializationContext());

now that ProductId string comes out like this: PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN

Is there a way to get the prodid to be set to the value I want?

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

It’s also possible to use ComponentSerializer instead of CalendarSerializer, which doesn’t have the issue.

val icalStr = (new ComponentSerializer()).SerializeToString(calendar);

Yep, just got bit by this too – if I’m specifically setting a ProductId then I want it rendered and may be looking for that value elsewhere to know that I’ve generated it.

IMO, the current method of just straight overriding is bad news. If you’re going to do that, make the property read only.

My proposal:

  • Make ProductId/Version properties read only
  • Restructure CalendarSerializer so that if you want to override the ProductId /Version you can derive your own CalendarSerializer and pass in the correct values

@rianjs I know you’re short on time, so I’m happy to do a PR to solve this, if it will be accepted.

@randbrown I am using the following code as a workaround:

const string productId = "-//my-company//My-Product//EN";
const string defaultProductId = "-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN";

var calendar = new Calendar
{
    ProductId = productId, // <-- makes no difference
    Method = "PUBLISH",
};

// ...

return new CalendarSerializer(calendar)
    .SerializeToString()
    // https://github.com/rianjs/ical.net/issues/408
    .Replace(defaultProductId, productId);