Repository navigation
Description
- Create .Net Core 2.2 Web App:
dotnet new webapp - Add NuGet Package:
Install-Package Unity.Microsoft.DependencyInjection - Customize Program:
WebHost.CreateDefaultBuilder(args) .UseUnityServiceProvider() .UseStartup<Startup>(); - Customize Startup:
services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddControllersAsServices(); - Run:
dotnet run
I have got:
Application startup exception: System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Reverse[TSource](IEnumerable1 source) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6] Application startup exception System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.Reverse[TSource](IEnumerable1 source)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Reverse[TSource](IEnumerable`1 source)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at _3.Program.Main(String[] args) in D:\TEMP\3\Program.cs:line 18
A similar problem is described here: #17
What have i done wrong?
FYI:
i have the problem with 5.9.2. (current release)
but not with 5.9.0.
Activity
ENikS commentedon Mar 14, 2019
Could you create a repo with code I could run and debug?
AndGa commentedon Mar 15, 2019
here:
GetStartedProblem.zip
H3xas commentedon Mar 15, 2019
I have the faced the same issue.
When I have added .UseUnityServiceProvider(_container) to CreateWebHostBuilder method, I received exactly same exception.
I have tried to make a workaround for that adding to CreateWebHostBuilder method following code:
Where BuildContainer() method, just returns instance of IUnityContainer.
That solved the issue with StartupFilters being not resolved, however it lead to issue with app.UseMvc() in Startup.cs. Firstly, it reported that it cannot get services from:
IEnumerable and if they were added in the same way as this "hack", it was notifying that it was empty.
ENikS commentedon Mar 15, 2019
If I disable Unity and run it with built-in DI it is still crushing with the following error:
I have feeling it is not the Unity container you have a problem with. Am I missing something?
AndGa commentedon Mar 16, 2019
dotnet restoredotnet runAnd now test it with 5.9.0 or with 5.9.1:
<PackageReference Include="Unity.Microsoft.DependencyInjection" Version="5.9.1" />dotnet restoredotnet runConclusion: current version 5.9.2 is not OK. Please find/fix wrong changes.
I suspect
.UseUnityServiceProvider.ENikS commentedon Mar 17, 2019
AndGa commentedon Mar 17, 2019
OK, forget my example, and make your own new "getting started" project with 5.9.2;
i make it so:
dotnet new webapp -n NewGettingStartedcd NewGettingStarteddotnet add package Unity.Microsoft.DependencyInjectiondotnet restoredotnet runmake changes from "Getting Started" page or
just add .UseUnityServiceProvider - you will get error.
Just make your new web app with .net core 2.2 and your 5.9.2. as you can. Forget my example project. Make your own one. Your will see: problem appear only with 5.9.2
AndGa commentedon Mar 17, 2019
I have found:
the ConfigureServices must return not void but IServiceProvider:
But ConfigureContainer will not be called !!!
AndGa commentedon Mar 18, 2019
But in case:
i get initial case: ConfigureContainer will be called but initial exception will be thrown.
:-(
if you try without ConfigureContainer - the same exception will be thrown:
ENikS commentedon Mar 18, 2019
@AndGa
It looks like Unity is failing to build RegistrPolicyResolver:
unitycontainer/microsoft-dependency-injection#38
Fixes #146