Migrate NServiceBus from older to latest version

Hi,
I am looking for help in migrating NServiceBus version 3.2.0.0 to 7.0.0.0. Following code is written in 3.2 which needs to be migrated to 7.0.

class clsName: IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
// Note: IConfigureThisEndpoint and AsA_Server are deprecated. and IWantCustomInitialization could not be loaded
{
public void Init()
{
Configure.With() // error: “The name ‘Configure’ does not exists in current context”
.DefaultBuilder()
.JsonSerializer();

SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
// error: “The name ‘SetLoggingLibrary’ does not exists in current context”

}
}

Any suggestions would be highly appreciated.
I see that configure.With() not supported and JsonSerializer() are not supported from 6.0.

Hi Kirans

We have still all the upgrade guides available on our documentation website

and so on. For you, it seems you are using the NServiceBus.Host. IConfigureThisEndpoint is a host-specific interface. So, the upgrade guide from the host would apply there:

Are you hosting NServiceBus in Windows Services? Are you also migrating to newer .NET versions? If that is the case, it might be worthwhile to migrate to the new generic host-based hosting model.

Which is mentioned in the deprecation notice of the NServiceBus.Host

For more detailed assistance, feel free to reach out to request non-critical support.

Regards
Daniel

Hi Danial, thanks for the quick reply.
Yes, the existing application is using host specific interface and we are hosting in windows service. And the .Net version used is 2013 with framework 2.0.
I tried to migrate to NServiceBus7 with framework 4.6.2. I am stuck at migrating following the code:
Configure.With()
.DefaultBuilder()
JsonSerializer();
If you have any alternate code for this please let me know and I will try to look into link given for upgrading 6 to 7.

Hi Kirans,

For the JSON part you should pull in NServiceBus.Newtonsoft.Json as a nuget package. Then you should be able to do

endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();

DefaultBuilder means NServiceBus is using the internal container. That should just work without you having to specify anything.

When you reach out to us via the above-mentioned non-critical support it might also be possible to share more of your code, should you still struggle, since that will be handled over our case management system and not be visible in the community forum here.

Regards,
Daniel

Thanks a lot Danial. This helped me to move further.
And I found the following in another file. Once again I need your help here.

Configure.With()
.DefaultBuilder()
.ForMvc()
.JsonSerializer()
.Log4Net()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.CreateBus()
.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

Hi Kiran,

.JsonSerializer()

same as in my above reply.

.Log4Net()

install NServiceBus.Log4Net and use LogManager.Use<Log4NetFactory>();

.MsmqTransport()

install NServiceBus.Transport.Msmq and use

var transport = endpointConfiguration.UseTransport<MsmqTransport>();
.IsTransactional(false)

translates to

transport.Transactions(...)

I’m no longer entirely sure which of the transaction modes it uses. I think it is SendsWithAtomicReceive but maybe @andreasohlund or @ramonsmits can clarify.

PurgeOnStartup(false)

is no longer needed since we don’t purge queues automatically.

.ImpersonateSender(false)

is no longer needed since by default we do not ad the WinIdName anymore.

.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

is just

endpointConfiguration.EnableInstallers();

Regards,
Daniel

would translate to

transport.Transactions(TransportTransactionMode.None)

Thank you so much @danielmarbach and @andreasohlund for your continues support. I will include these in my projects and let you know if any issues.

Hi,
Now showing message “name SetLoggingLibrary doesn’t exist in the current context” for the below line of code.
SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure)

Do I need to upgrade log4net or anything?

Hi,
I am using log4net.Config.XmlConfigurator.Configure(); for this.

And how do I migrate the following to 7.0

Configure.With()
.ForMvc()

where ForMvc() is
public static Configure ForMvc(this Configure configure)
{
// Register our controller activator with NSB
configure.Configurer.RegisterSingleton(typeof(IControllerActivator),
new NServiceBusControllerActivator());

        // Find every controller class so that we can register it
        var controllers = Configure.TypesToScan
            .Where(t => typeof(IController).IsAssignableFrom(t));

        // Register each controller class with the NServiceBus container
        foreach (Type type in controllers)
            configure.Configurer.ConfigureComponent(type, DependencyLifecycle.InstancePerCall);

        // Set the MVC dependency resolver to use our resolver
        DependencyResolver.SetResolver(new NServiceBusDependencyResolverAdapter(configure.Builder));

        return configure;
    }

please help me as configure is not available in 7.0