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: epositoryEdenredUKUK60Connect_BackendUK.ConnectUK.Connect.ClientServiceDynamicServiceDynamicProfileService.cs:line 35
at UK.Connect.ClientService.DynamicProfileService..ctor(IMapper mapper, IRemotingProxy proxy) in C: epositoryEdenredUKUK60Connect_BackendUK.ConnectUK.Connect.ClientServiceDynamicServiceDynamicProfileService.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: epositoryEdenredUKUK60Connect_BackendUK.ConnectUK.Connect.ClientServiceDynamicServiceDynamicProfileService.cs:line 35
at UK.Connect.ClientService.DynamicProfileService..ctor(IMapper mapper, IRemotingProxy proxy) in C: epositoryEdenredUKUK60Connect_BackendUK.ConnectUK.Connect.ClientServiceDynamicServiceDynamicProfileService.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);
        }
原文地址:https://www.cnblogs.com/chucklu/p/12557632.html