简体   繁体   English

Mono ASP.Net MVC EntityFramework异常

[英]Mono ASP.Net MVC EntityFramework Exception

I am trying to run my MVC application based on ASP.Net with the MVC 4 technology and the EntityFramework. 我正在尝试使用MVC 4技术和EntityFramework运行基于ASP.Net的MVC应用程序。

public ActionResult Test()
{
    DbEntities entities = new DbEntities();
    ViewBag.AddressBookList = entities.ADDRESSBOOK.Take(100).ToList();
    return View();
}

The problem is that I'm getting this exception when I'm calling /Home/Test. 问题是调用/ Home / Test时出现此异常。 It must be caused by the EntityFramework because the whole application works except to the point when I'm trying to retrieve data of the database with the EntityFramework. 这一定是由EntityFramework引起的,因为整个应用程序都可以正常工作,除非我尝试使用EntityFramework检索数据库的数据。 When I test it within Visual Studio (IIS) it runs properly without any error. 当我在Visual Studio(IIS)中测试它时,它可以正常运行,没有任何错误。

System Informations 系统信息

  • Windows 视窗
  • Net Framework 4.0 Net Framework 4.0
  • ASP .Net MVC 4 ASP .Net MVC 4
  • EntityFramework 6 实体框架6
  • Mono 3.2.3 (newest Windows version) Mono 3.2.3(最新Windows版本)
  • nginx FastCGI with fastcgi-mono-server4 nginx FastCGI与fastcgi-mono-server4

System.UriFormatException System.UriFormatException

Invalid URI: The format of the URI could not be determined: System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml 无效的URI:无法确定URI的格式:System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml

Stacktrace 堆栈跟踪

at System.Uri..ctor (System.String uriString, Boolean dontEscape) [0x00000] in <filename unknown>:0
at System.Uri..ctor (System.String uriString) [0x00000] in <filename unknown>:0
at Mono.Xml.Schema.XmlSchemaValidatingReader..ctor (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.CreateValidatingXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.CreateFilteredXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Xml.XmlReader.Create (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.Schema.Parse (System.Xml.XmlReader sourceReader, System.String sourceLocation) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerNotification, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerManifestTokenNotification, System.Data.Entity.Core.SchemaObjectModel.ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.Common.DbProviderManifest providerManifest, IList`1& schemaCollection) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest (System.Xml.XmlReader xmlReader, System.String location, Boolean checkForSystemNamespace, System.Data.Entity.Core.SchemaObjectModel.Schema& schema) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Data.Entity.SqlServer.SqlProviderManifest..ctor (System.String manifestToken) [0x00000] in <filename unknown>:0
at System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest (System.String versionHint) [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest (System.String manifestToken) [0x00000] in <filename unknown>:0 

This issue is caused by Entity Framework generating invalid XML. 此问题是由实体框架生成无效的XML引起的。 For some reason, Microsoft's implementation of XmlReader doesn't follow the spec while Mono's does. 由于某些原因,Microsoft的XmlReader实施不遵循规范,而Mono则遵循。 Fortunately for most Mono users, the issue was patched in Mono nearly a year ago. 幸运的是,对于大多数Mono用户而言,该问题已于一年前在Mono中修复。 You can view the pull request here: 您可以在此处查看拉取请求:

https://github.com/mono/mono/pull/756 https://github.com/mono/mono/pull/756

Unfortunately that doesn't help you since the latest version of Mono for Windows is over a year old. 不幸的是,这对您没有帮助,因为最新版本的Mono for Windows已经使用了一年多。 You can look at the issue in more depth at: 您可以在以下位置更深入地了解该问题:

https://entityframework.codeplex.com/workitem/1632 https://entityframework.codeplex.com/workitem/1632

Which may also help if you want to pull down the Entity Framework source and build from scratch with the patched code. 如果您想下拉实体框架源代码并使用修补的代码从头开始构建,这也可能会有所帮助。 If you can figure out the proper way, you may also be able to manually edit the offending XML so that it is valid and would no longer cause the Mono XML Reader to throw an Exception. 如果您可以找出正确的方法,则还可以手动编辑有问题的XML,使其有效并且不再导致Mono XML Reader引发异常。

Of course, since you're already running on Windows, you could simply use IIS and avoid the issue completely. 当然,由于您已经在Windows上运行,因此只需使用IIS即可完全避免该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM