Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I keep getting this error when I try to deserialize object. Code is below. The error occurs on the deserlalizefromstream() method below:

An exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll but was not handled in user code

Additional information: The input stream is not a valid binary format. The starting contents (in bytes) are: FF-D8-FF-E1-00-18-45-78-69-66-00-00-49-49-2A-00-08 ...
C#
public class Functions
   {
       // This function will get triggered/executed when a new message is written
       // on an Azure Queue called queue.
       //public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
       //{
       //    log.WriteLine(message);
       //}
       public static void ProcessRawFile(
       [QueueTrigger("thumbnailrequest")] BlobInformation blobInfo,
       [Blob("images/{BlobName}", FileAccess.Read)] Stream input,
       [Blob("images/{BlobNameWithoutExtension}_thumbnail.jpg")] CloudBlockBlob outputBlob)
       {
           using (Stream output = outputBlob.OpenWrite())
           {
               //do work
               // Retrieve storage account from connection string.
               var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());

               // Create the blob client.
               CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

               // Retrieve a reference to a container.
               CloudBlobContainer container = blobClient.GetContainerReference("images");

               // Retrieve reference to a blob named "myblob".
               CloudBlockBlob blob = container.GetBlockBlobReference("TestImage");


               MemoryStream ms = new MemoryStream();
               //Retrive the memorystream
               blob.DownloadToStream(ms);

               var rawFile = DeserializeFromStream(ms);
           }
       }
       private static MemoryStream SerializeToStream(object o)
       {
           MemoryStream stream = new MemoryStream();
           IFormatter formatter = new BinaryFormatter();
           formatter.Serialize(stream, o);
           return stream;
       }

       private static object DeserializeFromStream(MemoryStream stream)
       {

           IFormatter formatter = new BinaryFormatter();
           stream.Seek(0, SeekOrigin.Begin);
           object o = formatter.Deserialize(stream);
           return o;
       }
Posted
v2
Comments
CHill60 13-Dec-15 8:54am    
Sounds like your input isn't in binary format to me. Problem could be in DownloadToStream

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900