Make sure that the controller has a parameterless public constructor.


web調用了wcf,發現是wcf那邊出錯,連不上數據庫導致的。

數據庫的ip更換了

2020-04-17 14:53:04,873 ERROR [38]: controller:Logon, action:Logon
System.InvalidOperationException: An error occurred when trying to create a controller of type 'UKERecognition.Admin.Controllers.LogonController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DynamicProfileService (ReflectionActivator), Services = [UK.Connect.ClientService.IDynamicProfileService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(PetaPoco.IMapper, UK.Connect.ClientService.IRemotingProxy)' on type 'DynamicProfileService'. ---> Server error. Detail: Can not find program connection string by program id: 2 (See inner exception for details.) (See inner exception for details.) ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(PetaPoco.IMapper, UK.Connect.ClientService.IRemotingProxy)' on type 'DynamicProfileService'. ---> Server error. Detail: Can not find program connection string by program id: 2 (See inner exception for details.) ---> System.ServiceModel.FaultException: Server error. Detail: Can not find program connection string by program id: 2

 

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at LISA.InternalService.Contract.IAdminWebContract.AdminWebGetConnectionString(Int32 programID)
at LISA.Custom.Infrastructure.ProgramContract.GetConnectionStringById(Int32 programId)
at LISA.Custom.Infrastructure.ProgramContract.InitProgramInfo()
at LISA.Custom.Infrastructure.ProgramContract..ctor(IContractFactory contractFactory, Int32 programId, String currentLanguageCode, String currentCountryCode)
at UK.Connect.ClientService.DynamicProfileService.ConvertProxyToProgramContract(IRemotingProxy proxy) in C:\repository\Edenred\UK\UK60\Connect_Backend\UK.Connect\UK.Connect.ClientService\DynamicService\DynamicProfileService.cs:line 35
at UK.Connect.ClientService.DynamicProfileService..ctor(IMapper mapper, IRemotingProxy proxy) in C:\repository\Edenred\UK\UK60\Connect_Backend\UK.Connect\UK.Connect.ClientService\DynamicService\DynamicProfileService.cs:line 24
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.Core.Activators.Reflection.AutowiringPropertyInjector.InjectProperties(IComponentContext context, Object instance, IPropertySelector propertySelector, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Complete()
at Autofac.Core.Resolving.ResolveOperation.CompleteActivations()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType)
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 

2020-04-17 16:34:19,447 ERROR [13]:
System.InvalidOperationException: An error occurred when trying to create a controller of type 'UKERecognition.Admin.Areas.Incentive.Controllers.ErrorController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DynamicProfileService (ReflectionActivator), Services = [UK.Connect.ClientService.IDynamicProfileService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(PetaPoco.IMapper, UK.Connect.ClientService.IRemotingProxy)' on type 'DynamicProfileService'. ---> Server error. Detail: Can not find program connection string by program id: 2 (See inner exception for details.) (See inner exception for details.) ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(PetaPoco.IMapper, UK.Connect.ClientService.IRemotingProxy)' on type 'DynamicProfileService'. ---> Server error. Detail: Can not find program connection string by program id: 2 (See inner exception for details.) ---> System.ServiceModel.FaultException: Server error. Detail: Can not find program connection string by program id: 2

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at LISA.InternalService.Contract.IAdminWebContract.AdminWebGetConnectionString(Int32 programID)
at LISA.Custom.Infrastructure.ProgramContract.GetConnectionStringById(Int32 programId)
at LISA.Custom.Infrastructure.ProgramContract.InitProgramInfo()
at LISA.Custom.Infrastructure.ProgramContract..ctor(IContractFactory contractFactory, Int32 programId, String currentLanguageCode, String currentCountryCode)
at UK.Connect.ClientService.DynamicProfileService.ConvertProxyToProgramContract(IRemotingProxy proxy) in C:\repository\Edenred\UK\UK60\Connect_Backend\UK.Connect\UK.Connect.ClientService\DynamicService\DynamicProfileService.cs:line 35
at UK.Connect.ClientService.DynamicProfileService..ctor(IMapper mapper, IRemotingProxy proxy) in C:\repository\Edenred\UK\UK60\Connect_Backend\UK.Connect\UK.Connect.ClientService\DynamicService\DynamicProfileService.cs:line 24
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.Core.Activators.Reflection.AutowiringPropertyInjector.InjectProperties(IComponentContext context, Object instance, IPropertySelector propertySelector, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Complete()
at Autofac.Core.Resolving.ResolveOperation.CompleteActivations()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.Core.Activators.Reflection.AutowiringPropertyInjector.InjectProperties(IComponentContext context, Object instance, IPropertySelector propertySelector, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Complete()
at Autofac.Core.Resolving.ResolveOperation.CompleteActivations()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType)
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 

DynamicProfileService的接口和服務在Autofac中注冊過了。

創建Controller的時候,不知道為啥會自動Resolve對應的Service。

然后Service的實例需要連接數據庫,但是又找不到連接字符串。

需要研究一下autofac是如何在mvc中進行resolve操作的,是否不管注冊多少,在create controller的時候全部自動resolve


Application_Error方法里面會跳轉錯誤頁面

  Response.RedirectToRoute(new { controller = "Error", action = "Index" });

因為ErrorController也會觸發同樣的錯誤,直接死循環了。

 

https://github.com/autofac/Autofac.Mvc/blob/develop/src/Autofac.Integration.Mvc/AutofacDependencyResolver.cs#L172

目測是resolve這個DynamicProfileService的時候出錯了

  /// <summary>
        /// Get a single instance of a service.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <returns>The single instance if resolved; otherwise, <c>null</c>.</returns>
        public virtual object GetService(Type serviceType)
        {
            return this.RequestLifetimeScope.ResolveOptional(serviceType);
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM