Im trying to convert the nServiceBus PubSub .net4 example into vb and I’m struggling at one point which I think is a language issue but I thought I would ask the experts.
The code in question is from the publisher:
var eventMessage = publishIEvent ? Bus.CreateInstance<IEvent>() : new EventMessage();
When I try and run this in vb with
Public Property Bus As IBus
Dim eM As New EventMessage()
eM = Bus.CreateInstance(Of IEvent)()
I get a object refrence not set to an instance of the object error
But then I get an error saying I cant use new on an interface which iBus is
any ideas on how I get around this?
Given the similarities between c# and vb.net I cant believe this isnt possible?
Any ideas welcome
Thanks
Chris
The two parts of the conditional do not have the same type, but they are both assignable to
IEvent(I believe), which is the type the C# compiler will makeeventMessagehave. Try this:(probably not entirely correct syntax; my VB is getting rusty…)
(By the way, I’d suggest using the name
eventMessagein stead ofeM.)