Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Property or indexer 'Amqp.Message.Body' cannot be assigned to -- it is read only #36

Closed
jeffnuck opened this issue Feb 7, 2015 · 3 comments

Comments

@jeffnuck
Copy link

jeffnuck commented Feb 7, 2015

Running the NETMF/Gadgeteer code (no changes) and I get this compilation error on the following line of code:
message.Body = new Data() { Binary = Encoding.UTF8.GetBytes(payload) };

Error:
Property or indexer 'Amqp.Message.Body' cannot be assigned to -- it is read only...

Here is the code block:
void SendAMQPMessage(string payload)
{
try
{
// 0 indicates the method is not in use
if (0 == Interlocked.Exchange(ref IsSendingMessage, 1))
{
// Create the AMQP message
var message = new Message();
message.Properties = new Properties()
{
Subject = "wthr",
CreationTime = DateTime.UtcNow,
ContentType = "text/json",
};

                message.MessageAnnotations = new MessageAnnotations();
                message.MessageAnnotations[new Symbol("x-opt-partition-key")] = DeviceID;
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["time"] = message.Properties.CreationTime;
                message.ApplicationProperties["from"] = DeviceID;
                message.ApplicationProperties["dspl"] = DeviceName;
                //message.Properties.ContentType = "text/json";
                message.Body = new Data() { Binary = Encoding.UTF8.GetBytes(payload) };

                sender.Send(message);

                // release lock
                Interlocked.Exchange(ref IsSendingMessage, 0);
            }
        }
        catch (Exception e)
        {
            Debug.Print("Exception caught:" + e.Message);
        }
    }
@olivierbloch
Copy link
Contributor

Hi @jeffnuck , it seems the error appears when updating the AMQPNetLite library from 0.1.0-beta to 0.1.1-beta. I will investigate and push an update as soon as I can. In the meantime, you can revert the library to v 0.1.0-beta.
Let me know if this workaround works for you.

@olivierbloch
Copy link
Contributor

After giving it a quick look, it seems the library indeed changed a bit. The body has to be set in the constructor.
I will test later in the afternoon before pushing a patch, but in the meantime, you can try the following:

Change the line where we create the message object:
var message = new Message(new Data() { Binary = Encoding.UTF8.GetBytes(payload) });

and remove the one where we assign the body value.

@olivierbloch
Copy link
Contributor

Just committed patch along with the upgrade of the AMQPNetLite library version.
Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants