3
respostas

Erro ao executar o codigo do projeto fornecido ao final aula 3

ao descompactar e executar recebo a mensagem no browser:

Erro de Servidor no Aplicativo '/'.

Não foi possível carregar arquivo ou assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou uma de suas dependências. O sistema não pode encontrar o arquivo especificado.

Descrição: Ocorreu uma exceção sem tratamento durante a execução da atual solicitação da Web. Examine o rastreamento de pilha para obter mais informações sobre o erro e onde foi originado no código.

Detalhes da Exceção: System.IO.FileNotFoundException: Não foi possível carregar arquivo ou assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou uma de suas dependências. O sistema não pode encontrar o arquivo especificado.

Erro de Origem:

Exceção sem tratamento foi gerada durante a execução da atual solicitação da Web. As informações relacionadas à origem e ao local da exceção podem ser identificadas usando-se o rastreamento de pilha de exceção abaixo.

Rastreamento do Carregamento de Assembly: As informações a seguir podem ser úteis para determinar por que o assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' não pôde ser carregado.

=== Informações sobre estado pré-associação === LOG: DisplayName = Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/Users/lais.pereira/Downloads/desenvolvimento-web-asp-net-mvc-5-aula3/desenvolvimento-web-asp-net-mvc-5-aula3/CaelumEstoque-aula3/CaelumEstoque/ LOG: PrivatePath inicial = C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\bin

Chamando assembly: System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

LOG: esta associação começa no contexto de carregamento default. LOG: usando arquivo de configuração de aplicativo: C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\web.config LOG: usando arquivo de configuração de host: C:\Users\lais.pereira\Documents\IISExpress\config\aspnet.config LOG: usando arquivo de configuração da máquina de C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: referência pós-política: Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: tentando download de nova URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/7d71cb48/bc80ee79/Microsoft.Web.Infrastructure.DLL. LOG: tentando download de nova URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/7d71cb48/bc80ee79/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DLL. LOG: tentando download de nova URL file:///C:/Users/lais.pereira/Downloads/desenvolvimento-web-asp-net-mvc-5-aula3/desenvolvimento-web-asp-net-mvc-5-aula3/CaelumEstoque-aula3/CaelumEstoque/bin/Microsoft.Web.Infrastructure.DLL. LOG: tentando download de nova URL file:///C:/Users/lais.pereira/Downloads/desenvolvimento-web-asp-net-mvc-5-aula3/desenvolvimento-web-asp-net-mvc-5-aula3/CaelumEstoque-aula3/CaelumEstoque/bin/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DLL. LOG: tentando download de nova URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/7d71cb48/bc80ee79/Microsoft.Web.Infrastructure.EXE. LOG: tentando download de nova URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/7d71cb48/bc80ee79/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.EXE. LOG: tentando download de nova URL file:///C:/Users/lais.pereira/Downloads/desenvolvimento-web-asp-net-mvc-5-aula3/desenvolvimento-web-asp-net-mvc-5-aula3/CaelumEstoque-aula3/CaelumEstoque/bin/Microsoft.Web.Infrastructure.EXE. LOG: tentando download de nova URL file:///C:/Users/lais.pereira/Downloads/desenvolvimento-web-asp-net-mvc-5-aula3/desenvolvimento-web-asp-net-mvc-5-aula3/CaelumEstoque-aula3/CaelumEstoque/bin/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.EXE.

Rastreamento de Pilha:

[FileNotFoundException: Não foi possível carregar arquivo ou assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou uma de suas dependências. O sistema não pode encontrar o arquivo especificado.] System.Web.WebPages.PreApplicationStartCode.Start() +0 System.Web.Mvc.PreApplicationStartCode.Start() +32

[InvalidOperationException: O método de inicialização Start anterior ao início do aplicativo do tipo System.Web.Mvc.PreApplicationStartCode emitiu uma exceção com a seguinte mensagem de erro: Não foi possível carregar arquivo ou assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou uma de suas dependências. O sistema não pode encontrar o arquivo especificado..] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +615 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102 System.Web.Compilation.BuildManager.ExecutePreAppStart() +157 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): O método de inicialização Start anterior ao início do aplicativo do tipo System.Web.Mvc.PreApplicationStartCode emitiu uma exceção com a seguinte mensagem de erro: Não foi possível carregar arquivo ou assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou uma de suas dependências. O sistema não pode encontrar o arquivo especificado..] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Informações sobre a Versão: Microsoft .NET Framework Versão:4.0.30319; Versão do ASP.NET:4.6.1586.0

3 respostas

Oi Lais, tudo bom?

Tenta instalar essa dependencia:

Install-Package Microsoft.Web.Infrastructure

No projeto, pelo terminal do nuget.

Qualquer problema, compartilha com a gente!

Abraço e bons estudos =)

oi, instalei a dependência, ao tentar acessar /produto/index recebi o seguinte erro no browser:

Erro de Servidor no Aplicativo '/'.

An attempt to attach an auto-named database for file C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\App_Data\DBEstoque.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Descrição: Ocorreu uma exceção sem tratamento durante a execução da atual solicitação da Web. Examine o rastreamento de pilha para obter mais informações sobre o erro e onde foi originado no código.

Detalhes da Exceção: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\App_Data\DBEstoque.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Erro de Origem:

Linha 22: using (var contexto = new EstoqueContext()) Linha 23: { Linha 24: return contexto.Produtos.Include("Categoria").ToList(); Linha 25: } Linha 26: }

Arquivo de Origem: C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\DAO\ProdutosDAO.cs Linha: 24

Rastreamento de Pilha:

[SqlException (0x80131904): An attempt to attach an auto-named database for file C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\App_Data\DBEstoque.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.] System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +154 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +21 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +90 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) +217 System.Data.SqlClient.SqlConnection.Open() +96 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b38(DbConnection t, DbConnectionInterceptionContext c) +10 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Action2 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) +72 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +360 System.Data.Entity.Core.EntityClient.EntityConnection.b2() +55 System.Data.Entity.SqlServer.<>cDisplayClass1.b0() +10 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +189 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +78 System.Data.Entity.Core.EntityClient.EntityConnection.Open() +253

[EntityException: The underlying provider failed on Open.] System.Data.Entity.Core.EntityClient.EntityConnection.Open() +323 System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) +133 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +46 System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +155 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) +189 System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) +281 System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +11 System.Data.Entity.Internal.LazyEnumerator1.MoveNext() +45 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +275 System.Linq.Enumerable.ToList(IEnumerable1 source) +58 CaelumEstoque.DAO.ProdutosDAO.Lista() in C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\DAO\ProdutosDAO.cs:24 CaelumEstoque.Controllers.ProdutoController.Index() in C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\Controllers\ProdutoController.cs:16 lambda_method(Closure , ControllerBase , Object[] ) +61 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +157 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27 System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() +50 System.Web.Mvc.Async.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() +225 System.Web.Mvc.Async.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +26 System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765121 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Informações sobre a Versão: Microsoft .NET Framework Versão:4.0.30319; Versão do ASP.NET:4.6.1586.0

Oi Lais, seu sistema não está conseguindo encontrar seu banco no diretorio:

C:\Users\lais.pereira\Downloads\desenvolvimento-web-asp-net-mvc-5-aula3\desenvolvimento-web-asp-net-mvc-5-aula3\CaelumEstoque-aula3\CaelumEstoque\App_Data\DBEstoque.mdf

Verifica se o arquivo existe lá no diretório. Se não estiver tenta criar de novo o banco =)

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software