Posts

Showing posts with the label Azure Service Bus

Azure: Why is my blob 0KB when I move it?

I was archiving documents in Blob Storage and found that the target files were always being rendered as 0 KB. I was using the following code: var storageAccount = CloudStorageAccount.Parse("CONNECTIONSTRING"); var blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("container"); var blob = blobContainer.GetBlobReference("myfilename") // Get the source as a stream Stream stream = new MemoryStream(); blob.DownloadToStream(stream); var destBlob = blobContainer.GetBlockBlobReference(blob.Name); destBlob.UploadFromStream(stream); blob.Delete(); The code should work, except for the fact that the stream needs to be repointed to the start for the download to work. blob.DownloadToStream(stream); (from above) stream.Position = 0; And now the copy/move works

Azure Service Bus: Serialization operation failed due to unsupported type

When trying to add an object property to my Service Bus Queue, I encountered the following error: "Serialization operation failed due to unsupported type RichardLeeman.Model.MyObject." So I added the  [Serializable] annotation to the class, but to no avail. The issue seems to be that the property bag only likes simple types like int or string. So, my simple fix was to convert the class to JSON and put that in the bus. I used  System.Web.Script.Serialization.JavaScriptSerializer  to convert the object and placed the resulting string in the property bag. var client = QueueClient.CreateFromConnectionString(SERVICE_BUS_CNN, "myqueue"); var json = new JavaScriptSerializer().Serialize(myObjectInstance); var message = new BrokeredMessage("my test message"); message.Properties.Add(new KeyValuePair<string, object>("MyObjectProperty",json)); client.Send(message);