Code Monkey home page Code Monkey logo

aspnet-webapi's People

Contributors

eniks avatar fsimonazzi avatar rcdailey avatar sekiya9311 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aspnet-webapi's Issues

Intermittent NullReference Exceptions when creating Controllers

We have an infrequent but persistent issue with Unity.

Once every few thousand requests or so Unity throws a NullReference Exception when the attempting to construct the controller

Now these are requests that work as expected 99.9% of the time, so It's not that we haven't registered the dependencies, which is what I'd expect with this specific exception and message. Frankly I'm more than a little puzzled and would love some pointers on how to track down our issue.
The fact that it's infrequent and unpredictable makes isolating the issue very tricky.

Top Level Exception: System.InvalidOperationException - An error occurred when trying to create a controller of type 'SettingsController'. Make sure that the controller has a parameterless public constructor.

   at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
   at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.HttpServer.<SendAsync>d__24.MoveNext()

Inner Exception: Object reference not set to an instance of an object.
   at Unity.UnityContainer.<>c.<.ctor>b__73_2(BuilderStrategy[] chain, BuilderContext& context)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name)
   at Unity.Builder.BuilderContext.Resolve(ParameterInfo parameter, Object value)
   at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext& context)
   at Unity.UnityContainer.<>c.<.ctor>b__73_2(BuilderStrategy[] chain, BuilderContext& context)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name)
   at Unity.Builder.BuilderContext.Resolve(ParameterInfo parameter, Object value)
   at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext& context)
   at Unity.UnityContainer.<>c.<.ctor>b__73_2(BuilderStrategy[] chain, BuilderContext& context)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name)
   at Unity.Builder.BuilderContext.Resolve(ParameterInfo parameter, Object value)
   at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext& context)
   at Unity.UnityContainer.<>c.<.ctor>b__73_1(BuilderContext& context)
   at Unity.UnityContainer.Unity.IUnityContainer.Resolve(Type type, String name, ResolverOverride[] overrides)
   at Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides)
   at Unity.AspNet.WebApi.UnityDependencyResolver.SharedDependencyScope.GetService(Type serviceType)
   at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
   at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)

未能加载文件或程序集“Unity.AspNet.WebApi, Version=5.0.1.9, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”或它的某一个依赖项

未能加载文件或程序集“Unity.AspNet.WebApi, Version=5.0.1.9, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
[FileLoadException: 未能加载文件或程序集“Unity.AspNet.WebApi, Version=5.0.1.9, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)]
VOCs.WebAPI.App_Start.UnityWebApiActivator.Start() in H:\VOCs\03_Code\00_SourceCode\VOCsV2\06_Web\WebAPI\App_Start\UnityWebApiActivator.cs:20

[TargetInvocationException: 调用的目标发生了异常。]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +114
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +146
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +81
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +699
WebActivatorEx.ActivationManager.Run() +123

[InvalidOperationException: 针对类型 WebActivatorEx.ActivationManager 的应用程序预启动初始化方法 Run 引发了异常,显示下列错误消息: 调用的目标发生了异常。。]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +902
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +169
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +173
System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +912

[HttpException (0x80004005): 针对类型 WebActivatorEx.ActivationManager 的应用程序预启动初始化方法 Run 引发了异常,显示下列错误消息: 调用的目标发生了异常。。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +534
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +718

Unity.AspNet.WebApi, Version=5.0.2.17,Unity.Abstractions, Version=2.0.2.67

错误 CS1705 标识为“Unity.AspNet.WebApi, Version=5.0.2.17, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”的程序集“Unity.AspNet.WebApi”所使用的“Unity.Abstractions, Version=2.0.2.67, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”版本高于所引用的标识为“Unity.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f”的程序集“Unity.Abstractions” VOCs.WebAPI H:\WebAPI\App_Start\UnityWebApiActivator.cs 17 活动的

Inject Current HttpRequestMessage thru Unity WebApi

This is NOT an issue but a request, Put in Issue per Eugene's recommendation.
Dear Unity WebApi Authors, Thanks for the great Unity WebApi package, makes my life simple!! I have a quick question, this is my setup Project: AspNet WebApi2, .netframework 4.7, Unity Asp WebAPI latest as the IOC tool I have a class like below

public class Logger: ILogger { 
private readonly HttpRequestMessage request;
// Current HttpRequestMessage to be injected by Unity
public Logger(HttpRequestMessage request)
{
    this.request = request;
} }

I would like to USE Unity/Unity WebAPI package to inject Current HttpRequestMessage thru IOC above for every request

  1. what is the correct way to do this? Sample code and where to register this dependency would be helpful.
  2. Can I do this registration at Appstart when there is no request?
  3. I know Autofac has an extension to do this but I would like to use Unity.

Can you Please reply soon as I am stuck on this for sometime. Kindly let me know any questions. Thanks again and keep up the great work.

Thanks, Sanjev Saalaivazan

missing PerRequestLifetimeManager in Unity.AspNet.WebApi

When using Unity with ASP.NET Web API project i added the following packages

  <package id="Unity" version="5.8.5" targetFramework="net471" />
  <package id="Unity.Abstractions" version="3.3.0" targetFramework="net471" />
  <package id="Unity.AspNet.WebApi" version="5.0.13" targetFramework="net471" />
  <package id="Unity.Container" version="5.7.0" targetFramework="net471" />
  <package id="WebActivatorEx" version="2.2.0" targetFramework="net471" />

However, I can not use PerRequestLifetimeManager because it is not part of Unity.AspNet.WebApi. Instead PerRequestLifetimeManager is part of Unity.Mvc. and when Unity.Mvc Nuget package is added to Web Api Project it brings in other Web UI related dependencies like

Microsoft.AspNet.Razor
Microsoft.AspNet.WebPages
Microsoft.AspNet.Mvc

Is there a way to use PerRequestLifetimeManager in ASP.NET Web API without adding Unity.Mvc package?

Dependency on Micrsoft.AspNet.WebApi.WebHost not always needed

UnityDependencyResolver can also be used with a self-hosting on OWIN
but this package has a dependency on Microsoft.AspNet.WebApi which in its turn
depends on Microsoft.AspNet.WebApi.WebHost.
UnityDependencyResolver, however, has no dependency on any particular hosting environment.
Please, consider extracting UnityDependencyResolver into a separate package.

Unity.AspNet.Webapi v5.11.1 global asax question?

Hi,

I am trying to use Unity.AspNet.Web API v5.11.1 as IOC container. Couldn't figure it out if I should add something about unity on Application Start. I couldn't find examples, please guide me.

Thanks.

Web API Dependency Injection with Unity error - No public constructor is available for type System.Web.Http.Dispatcher.IHttpControllerActivator

I am trying to implement the dependency injection in ASP.Net web API with unity container and have implemented the exactly with below 2 articles:

  1. https://stackoverflow.com/a/38770689/3698716
  2. https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/dependency-injection

Both are related to each other with some minor change but implementation for both are the same.

After implementing I am getting an error in the method GetService in UnityResolver.cs class:

"Resolution failed with error: No public constructor is available for type System.Web.Http.Dispatcher.IHttpControllerActivator."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.