Hello, I became aware of something in Dynamics programming through C#. It is about setting the state as well as status code through the script.

Although all permissions are given for both read and write, I get the exception/error : "This entity is readonly." The setting of the state and status code is done as follows:

entity["statecode"] = new OptionSetValue(0);
entity["statuscode"] = new OptionSetValue(1);

The interesting thing is that this way works in many other examples... but not for the "invoice" entity. So what is being done? I tried this with the SetStateRequest class - which also eventually led to success.

SetStateRequest setStateRequest = new SetStateRequest()
    EntityMoniker = new EntityReference
        Id = invoice.Id,
        LogicalName = "invoice",
    State = new OptionSetValue(0),
    Status = new OptionSetValue(1)


Now my question about this - what is the crucial reason that the top lines of code point to "readonly" and the bottom one works. Is this possibly just a "bug" or is there something behind it?

Thank you and have a pleasant day.