单声道ASP.Net MVC EntityFramework异常

时间:2014-10-10 14:10:07

标签: c# asp.net asp.net-mvc entity-framework mono

我正在尝试使用MVC 4技术和EntityFramework运行基于ASP.Net的MVC应用程序。

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

问题是我在调用/ Home / Test时遇到此异常。它必须由EntityFramework引起,因为除了尝试使用EntityFramework检索数据库的数据之外,整个应用程序都可以工作。当我在Visual Studio(IIS)中测试它时,它运行正常,没有任何错误。

系统信息

  • Net Framework 4.0
  • ASP .Net MVC 4
  • EntityFramework 6
  • Mono 3.2.3(最新的Windows版本)
  • nginx FastCGI with fastcgi-mono-server4

System.UriFormatException

  

无效的URI:无法确定URI的格式:   System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml

堆栈跟踪

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 

1 个答案:

答案 0 :(得分:0)

此问题是由Entity Framework生成无效XML引起的。出于某种原因,微软的XmlReader实现并没有遵循规范,而Mono的确如此。对于大多数Mono用户来说幸运的是,这个问题在近一年前在Mono中得到了补丁。您可以在此处查看拉取请求:

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

不幸的是,由于Mono for Windows的最新版本已超过一年,因此对您没有帮助。您可以更深入地查看该问题:

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

如果您想要下载实体框架源并使用修补代码从头开始构建,这也可能有所帮助。如果你能找到正确的方法,你也可以手动编辑有问题的XML,使其有效,不再导致Mono XML Reader抛出异常。

当然,由于您已经在Windows上运行,因此您可以简单地使用IIS并完全避免此问题。