【发布时间】:2023-04-05 09:20:02
【问题描述】:
我将 ASP.NET MVC 应用程序解决方案拆分为 3 个项目:
- MyApp.Domain(EDMX 文件和存储库)
- MyApp.Test(单元测试)
- MyApp.WebUI(MVC 应用)
当我让我的应用程序脱离源代码控制,将项目MyApp.WebUI 设置为启动项目并按 F5 运行时,我的 DbContext 出现错误...
“System.InvalidOperationException”类型的异常发生在 mscorlib.dll 但未在用户代码中处理
附加信息:实体框架提供程序类型 'MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity.EF6' 在 ADO.NET 提供程序的应用程序配置文件中注册 无法加载具有不变名称“MySql.Data.MySqlClient”。制作 确保使用了程序集限定名称并且程序集是 可用于正在运行的应用程序。看 http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息。
但是,如果我先在我的MyApp.Domain 项目上单击鼠标右键并“构建”然后运行它,我的应用程序就可以很好地建立连接。
难道我不应该只单击运行,它就应该将它们全部构建并正常工作吗?
更新 1
如果我从构建菜单中选择“全部重建”或“构建解决方案”,我认为这应该单独重建我的所有项目,但在我运行它时会出现错误。
我必须在 VS 中对我的 MyApp.Domain 项目实际选择“构建”,然后按 F5 我的解决方案,以便我的应用程序在没有 DbContext 错误的情况下连接到数据库。
更新 2
如果我用鼠标右键单击我的 EDMX 文件并“运行自定义工具”(如 Microsoft article to regenerate the EDMX code 中所建议的那样),然后按 F5 键运行我的解决方案,它仍然无法运行。我也试过打开 EDMX 并保存它。它仍然会出现 DbContext 错误。
更新 3 - 应用配置文件
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="QuizEntities" connectionString="metadata=res://*/QuizModel.csdl|res://*/QuizModel.ssdl|res://*/QuizModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;database=uquiznew"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AppStartup" value="uQuiz.OwinStart" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
【问题讨论】:
-
可能
Domain项目似乎已过时,因为它是一个依赖项,Visual Studio 需要“刷新”。 -
我的解决方案脱离了源代码控制,我想知道这是否会影响它..?当你说它已经过时了,你的意思是,当我按 F5 时它不应该构建我所有的项目吗?
-
可能是
edmx构建添加了一个生成步骤,否则会丢失。 -
你是唯一一个参与这个项目的人吗?项目可以由其他开发人员修改吗?我不是这方面的专家,我只是在这里猜测,但我认为
Run充其量只是进行增量构建。 -
是的,我是唯一一个工作的人,我在我自己的个人 SVN 存储库中拥有它:)。
标签: .net asp.net-mvc entity-framework dbcontext edmx