2016-03-03 25 views
0

我最近降级了一个应用程序使用.net 4.5.1到4.0,安装应用程序并运行后,我得到以下错误!系统找不到指定的文件(确保控制器有一个无参数的公共构造函数)

令人惊讶的是,同样的应用程序在我的本地机器上工作,但它不会在测试机器上运行。我的本地机器安装了.net 4.5.1,测试机器安装了相同的.net版本。

目前我有一个控制器(A),它从一个基本控制器继承而来,并且这个基础控制器确实有一个无参数的公共构造函数,并在那里进行一些映射。


The system cannot find the file specified

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) +6568558 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +6595000 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +219 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6597350 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6597891 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +942 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1162 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +72 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +6601145 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +103 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2102 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1079 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +6605639 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry) +233 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry) +278 System.Data.SqlClient.SqlConnection.Open() +239 System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch(TTarget target, Action 2 operation, TInterceptionContext interceptionContext, Action 3 executing, Action 3 executed) +207 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +438 System.Data.Entity.SqlServer.<>c__DisplayClass33.b__32() +582 System.Data.Entity.SqlServer.<>c__DisplayClass1.b__0() +15 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func 1 operation) +263 System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action 1 act) +749 System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable 1 commandTimeout, StoreItemCollection storeItemCollection) +314 System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +326 System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +230 System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func 3 createMigrator, ObjectContext objectContext) +129 System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +267 System.Data.Entity.CreateDatabaseIfNotExists 1.InitializeDatabase(TContext context) +217 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +596 System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input) +208 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action 1 action) +263 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +38 System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() +72 System.Data.Entity.Internal.Linq.InternalSet 1.get_InternalContext() +21 System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() +64 System.Linq.Queryable.Where(IQueryable 1 source, Expression 1 predicate) +85 OnlinePolicySales.Operations.CacheManager.get_Translations() +440 OnlinePolicySales.Operations.Extensions.LocalizationExtensions.Translate(String IdString, String[] args) +49 OnlinePolicySales.Web.Attributes.RequiredIfAttribute..ctor(String otherProperty, Comparison comparison, Object value, String modelPrefix) +260 System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) +0 System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs) +77 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1294 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType) +149 AutoMapper.ConfigurationStore.CreateMappingExpression(TypeMap typeMap, Type destinationType) +253 AutoMapper.ConfigurationStore.CreateMap(Type sourceType, Type destinationType, MemberList memberList) +27 OnlinePolicySales.Web.Helpers.MapperHelper.MapModelsToViewModels() +247 OnlinePolicySales.Web.Controllers.BaseController..ctor() +79

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256 System.Activator.CreateInstance(Type type, Boolean nonPublic) +127 System.Activator.CreateInstance(Type type) +78 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +92

[InvalidOperationException: An error occurred when trying to create a controller of type 'OnlinePolicySales.Web.Controllers.BaseController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +256 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +81 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +270 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +86 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12288259 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

+0

是你的基础控制器抽象类吗?如何定义无参数构造函数? – cdie

+0

不,它不是抽象类。 '代码 公共类BaseController:控制器 { 公共BaseController() { MapperHelper.MapModelsToViewModels(); MapperHelper.MapViewModelsToModels(); } ...}' – hadi

回答

0

看起来你有一些设置来创建数据库。请注意,错误在你的堆栈跟踪:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible

确保您的数据库连接字符串指向一个数据库或服务器是您要运行该代码的环境中访问

我觉得public parameterless constructor。在这种情况下,错误有点误导。

相关问题