0

I need to implement some Azure storage queue functions into an existing VB.Net windows forms app. Everything was working great until I ran into a Base64 encoding issue, finding this message in my Azure function log:

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

I found this post on how to do this in C#, but I can't figure out how to do it in VB.NET.

This is valid syntax - at least it's accepted without error by the interpreter in Visual Studio, anyway:

Dim qc As QueueClient = New QueueClient(connstr, "licensecreationqueue", New QueueClientOptions)

But I need to implement Base64 encoding as per this bit of code from that other post:

_queue = new QueueClient(connectionString, queueName, new QueueClientOptions
{
    MessageEncoding = QueueMessageEncoding.Base64
});

I just can't figure out the syntax on how to incorporate the QueueMessageEncoding.Base64 into the constructor, and none of the online converters (Telerik et al.) are able to resolve it.

technonaut
  • 484
  • 3
  • 12
  • Please see if this helps: https://social.msdn.microsoft.com/forums/en-US/9b1bd1bf-b77c-4010-bc03-03f92a3a4df7/setting-object-properties-in-the-constructor-vbnet. – Gaurav Mantri Mar 31 '21 at 14:26
  • No, because the [QueueClient class](https://learn.microsoft.com/en-us/dotnet/api/azure.storage.queues.queueclient.-ctor?view=azure-dotnet) doesn't have any matching properties you can set in that manner. – technonaut Mar 31 '21 at 14:31

1 Answers1

0

I just figured it out. QueueClientOptions is its own distinct class with its own properties, so you have to create it and then pass it to the QueueClient when you create it. Posting solution in case it helps someone else:

Dim connstr As String = "My Connection String"
Dim queuename as string = "myqueue"
Dim qco As New QueueClientOptions
qco.MessageEncoding = QueueMessageEncoding.Base64
Dim qc As QueueClient = New QueueClient(connstr, queuename, qco)
technonaut
  • 484
  • 3
  • 12
  • 2
    BTW, this will also work: `Dim queueClient As QueueClient = New QueueClient(connstr, queueName, New QueueClientOptions() With {.MessageEncoding = QueueMessageEncoding.Base64})` – Gaurav Mantri Mar 31 '21 at 14:52