Send commands from vb.net WebForms (.NET Framework 4.6.1)

My team would like to use NServiceBus to send commands from our legacy website’s UI, which uses vb.net WebForms and targets .NET Framework 4.6.1.
Is this possible? If not, what’s the best workaround?

Hi John,

A version of NServiceBus targeting .NET 4.6.1 should be fine (the minimum version of the .NET Framework supported is currently 4.5.2). A send-only endpoint should work fine. Have you faced any problems?

Admittedly I haven’t used vbnet in a while, but I managed to create the send-only endpoint just fine. The sent vbnet command object isn’t deserializing into the C# command object at the receiving endpoint.

This is the error on the receiving C# endpoint:

NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from incoming physical message 744b8f38-68ce-4057-957e-aed9017829cd
 ---> System.Exception: Could not determine type for node: 'DoSomethingCommand'.

I can send the C# command between endpoints that use C# without any problems because the command objects are perfectly identical between the two endpoints and written in the same language. In ServiceInsight, this is what the successfully-received C# command body looks like:

<DoSomethingCommand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:baseType="EventBus.API.Commands.IntegrationCommand" xmlns="http://tempuri.net/Messaging.Commands">
  <WhatShouldHappen>string</WhatShouldHappen>
  <ID>3fa85f64-5717-4562-b3fc-2c963f66afa6</ID>
  <CreatedDate>2022-07-21T20:41:35.247Z</CreatedDate>
</DoSomethingCommand>

This is the body of the sent vbnet command that fails to deserialize into the C# command object at the receiving endpoint:

<DoSomethingCommand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:baseType="IntegrationCommand" xmlns="http://tempuri.net/">
  <WhatShouldHappen>string</WhatShouldHappen>
  <ID>8d8bbfce-8fdb-4237-9647-de19810580ad</ID>
  <CreatedDate>2022-07-21T22:49:31.62219Z</CreatedDate>
</DoSomethingCommand>

(I can see that my custom namespaces are missing from the “xmlns:baseType” and “xmlns” even though I included them in the vb.net command object and “IntegrationCommand” class)

Here’s the DoSomethingCommand in C#:

namespace Messaging.Commands
{
    public class DoSomethingCommand : IntegrationCommand
    {
        public DoSomethingCommand()
        {
        }

        public DoSomethingCommand(string command)
        {
            WhatShouldHappen = command;
        }

        public string WhatShouldHappen { get; set; }
    }
}

Here’s the vbnet version being sent:

Imports Microsoft.VisualBasic
Imports NServiceBus

Namespace Messaging.Commands
End Namespace

Public Class DoSomethingCommand : Inherits IntegrationCommand

    Public Sub New()
    End Sub

    Public Sub New(command As String)
        WhatShouldHappen = command
    End Sub
    Public Property WhatShouldHappen As String
End Class

John,

From my recollection of VB.NET, the way you declare namespaces are not correct. Your types need to be wrapped inside the declared namespace. It should look like this:

Imports Microsoft.VisualBasic
Imports NServiceBus

Namespace Messaging.Commands
    Public Class DoSomethingCommand : Inherits IntegrationCommand

        Public Sub New()
        End Sub

        Public Sub New(command As String)
            WhatShouldHappen = command
        End Sub
        Public Property WhatShouldHappen As String
    End Class
End Namespace

Please see if that works?

When I said that I hadn’t used vbnet in a while, I wasn’t kidding… :sweat_smile:
This was the issue.

Thank you.

1 Like