"Unable to resolve type: System.Threading.Tasks.Task" exception in WebApi application
See original GitHub issueI’m trying to resolve my own OAuthAuthorizationServerProvider for injecting it into OAuthOptions in my application. But I’m getting a strange exception on app start. I’ve tried many cases, and it works if I use RegisterInstance method.
Server Error in '/' Application.
Unable to resolve type: System.Threading.Tasks.Task, service name:
[InvalidOperationException: Unable to resolve type: System.Threading.Tasks.Task, service name: ]
LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError) in c:\GitHub\LightInject\NuGet\Build\Net45\LightInject\LightInject.cs:3999
LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError) in c:\GitHub\LightInject\NuGet\Build\Net45\LightInject\LightInject.cs:3970
LightInject.ServiceContainer.GetInstance(Type serviceType, Object[] arguments) in c:\GitHub\LightInject\NuGet\Build\Net45\LightInject\LightInject.cs:2675
LightInject.ServiceContainer.GetInstance(T value) in c:\GitHub\LightInject\NuGet\Build\Net45\LightInject\LightInject.cs:2736
Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerProvider.MatchEndpoint(OAuthMatchEndpointContext context) +10
Microsoft.Owin.Security.OAuth.<InvokeAsync>d__0.MoveNext() +421
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +383
Steps to reproduce (easy):
- Create a new standard ASP.Net 4.5.2 Template “Web API” solution
- Add package “LightInject.WebApi 1.0.0.4”
- Open “ApplicationOAuthProvider.cs” and remove all constructors
- Open “Startup.Auth.cs”, change creation of OAuthOptions to the following and start the application:
var container = new ServiceContainer();
container.Register<ApplicationOAuthProvider, ApplicationOAuthProvider>();
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = container.GetInstance<ApplicationOAuthProvider>(), // this is the modified line
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
<package id="LightInject" version="3.0.2.7" targetFramework="net452" />
<package id="LightInject.WebApi" version="1.0.0.4" targetFramework="net452" />
Project target: .Net Framework 4.5.2 "Any CPU"
Windows 10 x64, VS 2015
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Dependency Injection error: Unable to resolve service for ...
I created an .NET Core MVC application and use Dependency Injection and Repository Pattern to inject a repository to my controller. However, I ......
Read more >ASP.Net Core API Error (Unable to resolve service for type ' ...
I built a Web API using ASP.Net Core (from Microsoft Tutorial). When calling the API, I got this error below: The error can...
Read more >Unable to resolve service for type '' while attempting to ...
What am I missing? What I have tried: I have tried rearranging the order of services in the container but the error still...
Read more >Unable to resolve service for type while attempting ...
In my ASP.NET Core application, I get the following error: InvalidOperationException: Unable to resolve service for type 'Cities.Models.
Read more >Unable to resolve service for type while attempting ...
A C# code example that shows how to correct the ASP.NET Core Dependency Injection error: 'Unable to resolve service for type while attempting...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can also disable property injection at the container level
@kbiel Thanks for clarification!