Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Upgrading the Unity.Container dependency will cause a NullReferenceException when starting up #108

Closed
Scooletz opened this issue Apr 25, 2019 · 8 comments · Fixed by #110
Labels
Milestone

Comments

@Scooletz
Copy link

Scooletz commented Apr 25, 2019

Who's affected

All customers upgrading to Unity 5.10.x and higher

Symptoms

Upgrading Unity to a newer minor (e.g. v5.11.1 but not limited to this version) has broken the factory resolution. The current nuget range allows people to upgrade to this version and that will cause a NullReferenceException cascade at startup

Workaround

Downgrade unity to previous versions

Analysis

A customer reported that when they bumped up the Unity to 5.10.3 the following exception occurred:

Exception Object reference not set to an instance of an object.

at NServiceBus.ReceiveComponent.AddReceivers() in C:\BuildAgent\work\ed946b9f0e4aae01\src\NServiceBus.Core\Receiving\ReceiveComponent.cs:line 146

at NServiceBus.ReceiveComponent.Initialize() in C:\BuildAgent\work\ed946b9f0e4aae01\src\NServiceBus.Core\Receiving\ReceiveComponent.cs:line 68

at NServiceBus.StartableEndpoint.Start() in C:\BuildAgent\work\ed946b9f0e4aae01\src\NServiceBus.Core\StartableEndpoint.cs:line 32

@gustavnyberg
Copy link

We are experiencing the same issue with all versions back to at least Unity 5.9.7. We have been waiting in version 5.8.13 until all our third parties had fixed the breaking changes in Unity in their own dependencies. The same code but with the MS Dependecy Injection implementation works just fine.

We have already bumped all our packages to the latest versions of both Unity and NServiceBus, since we considered it solved and stable. And I would really prefer not to go through the process of rolling everything back.

Please keep us posted on any progress, if you need any input from us and if not able to solve the problem at least give us a hint regarding what could give this error.

Thanks in advance.

Regards,
Gustav

@gustavnyberg
Copy link

gustavnyberg commented Apr 26, 2019

I have investigated the problem further and kept on trying to isolate the problem and making sure that the problem really is in your and not our code.

I have now and established that it most certainly is in your code and that the problem most likely lies in differences in what Endpoint.Create(endpointConfiguration), IStartableEnpoint.Start() in NServiceBus expects and what endpointConfiguration.UseContainer() hands them.

I have ruled everything specific to our code and the following test case reproduces the issue.

[Test]
public async Task SamplesUnity_UnityContainer_DoesNotThrow()
{
    const string license = //insert license
    const string connectionString = //insert connection string

    var endpointConfiguration = new EndpointConfiguration(endpointName: "unity-samples");
    endpointConfiguration.License(license);
    endpointConfiguration.UsePersistence<InMemoryPersistence>();
    endpointConfiguration.SendFailedMessagesTo(errorQueue: "unity-samples-centralized-error-queue");
    endpointConfiguration.EnableInstallers();
    endpointConfiguration.UseContainer<UnityBuilder>();

    var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
    transport.ConnectionString(connectionString);
    transport.TopicName(topicName: "unity-samples-topic");
    
    var startableEndpoint = await Endpoint.Create(endpointConfiguration);
    Assert.DoesNotThrowAsync(async () => await startableEndpoint.Start());
}

I would really appreciate some feedback on how things is progressing on your side and when we can expect a fix rolled out for this given that you can find what causes it.

Thanks in advance!

Regards,
Gustav

@gustavnyberg
Copy link

gustavnyberg commented May 2, 2019

Any updates regarding this issue?

Regards,
Gustav

@WojcikMike
Copy link

hi @gustavnyberg can you please let me know what NServiceBus.Unity version are you using while encountering errors with previous errors of Unity (pre 5.10.3)?

We are aware of this issue exist in NServiceBus.Unity 10.0.0 and Unity 5.10.3. The latest NServiceBus.Unity version should work for supported Unity packages lower than 5.10.3

@gustavnyberg
Copy link

gustavnyberg commented May 9, 2019

I am using NServiceBus.Unity 10.0.0.

The problem is present at least as far back as Unity (5.9.7).

I have tried every version of Unity from 5.9.7 up to 5.10.3 and I am getting the same error.

Due to other chained dependencies I can't go back further than Unity 5.9.7.

But the last working version for us was Unity 5.8.13 which was before the first severe breaking change in Unity.

The same goes for NServiceBus.

Last working versions were:

<PackageReference Include="NServiceBus" Version="7.1.6" />
<PackageReference Include="NServiceBus.Unity" Version="9.0.0" />
<PackageReference Include="Unity.Container" Version="5.8.13" />

@WojcikMike
Copy link

@gustavnyberg thank you for your response. Unfortunately, I was unable to encounter errors on the version that you specified.

I copied the code from our Samples and changed the transport to ASB, feel free to try it out: https://github.com/WojcikMike/UnitySample

On my end the only combination of versions that it doesn't work for is NServiceBus.Unity 10.0.0
and Unity.Container 5.10.3. Would you be so nice to verify if this is the same for you with this code base?

The reason why I got hung up on that is that what you say (that Unity throws an exception on every version from 5.9.7) is something new to us and I would like to verify this before moving forward with this issue.

The code requires connection string to ASB.

@gustavnyberg
Copy link

@WojcikMike

I have tried the samples you sent.

The .Net Framework project works.

The Core version does not build. You are missing two Nuget packages:

  • NServiceBus.Newtonsoft.Json

  • NServiceBus.Transport.AzureServiceBus

You also need to replace transport.UseForwardingTopology() since that extension method is a part of the NServiceBus.Azure.Transports.WindowsAzureServiceBus Nuget package, which seems to be missing a Core implementation.

I have made some alterations to fix the build errors in the Core project and been able to build it and once able to build and run it, it also works.

I have also tried running our test case and the sample projects and they are working too.

Unfortunately we haven't been able to wait for the feedback from you risking having a late release and last minute fixes.

So we have proceeded by replacing Unity with an in-house .Net Framework compatible implementation of Microsoft's .Net Core Dependency Injection Framework.

I have tried recreating the old conditions by reverting these changes, but I am not 100% sure I have managed to do so.

Anyway, now I am not able to reproduce the error for any other combinations than NServiceBus.Unity 10.0.0 and Unity.Container 5.10.3.

Since we have been able to completely replace Unity and since we no longer can reproduce the error I don't see that there is much left to do but to make the changes I suggested to your sample projects (which are very nice to have when troubleshooting) and maybe add a .Net Standard sample too, then close this particular issue and to fix it for NServiceBus.Unity 10.0.0 and Unity.Container 5.10.3.

Regards,
Gustav

@HEskandari
Copy link
Contributor

HEskandari commented Jun 28, 2019

I have reproduced this locally as well using Unity.Container v5.11.1. The issue appears to be related to how singleton instance factories are resolved from the container. A failing test has been submitted here.

@danielmarbach danielmarbach added this to the 10.1.0 milestone Jul 30, 2019
@danielmarbach danielmarbach changed the title Unity 5.10.3 potentially breaks things Upgrading the Unity.Container dependency will cause a NRE when starting up Jul 30, 2019
@danielmarbach danielmarbach changed the title Upgrading the Unity.Container dependency will cause a NRE when starting up Upgrading the Unity.Container dependency will cause a NullReferenceException when starting up Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants