当我尝试将我的 Web API 项目部署到 Azure 上的云网站和云托管服务时出现此错误:
"{"ExceptionType":"System.TypeLoadException","Message":"Could not load type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.","StackTrace":"\r\nServer stack trace: \r\n at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)\r\n at System.Reflection.RuntimeAssembly.GetExportedTypes()\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.WebHost.WebHostHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()\r\n at System.Lazy`1.CreateValue()\r\n\r\nException rethrown at [0]: \r\n at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)\r\n at System.Reflection.RuntimeAssembly.GetExportedTypes()\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.WebHost.WebHostHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()\r\n at System.Lazy`1.CreateValue()\r\n at System.Lazy`1.LazyInitValue()\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()\r\n at System.Lazy`1.CreateValue()\r\n\r\nException rethrown at [1]: \r\n at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"}"
这里只是消息:
"Could not load type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."
当我尝试从远程站点访问我的任何 API 时,就会发生这种情况。我知道这不是我的 500 错误,因为无论发生什么,我的一些 API 都不会抛出它们。
需要注意的一件事,我不确定这是否会影响任何事情,我开始这个项目的目标是 .NET 4.5,但是当 Azure 网站说他们不支持 4.5 时,将其切换到 4.0。
除了这个链接,我什么也找不到:http: //support.appharbor.com/discussions/problems/4822-internal-server-error-500-mvc-4-web-api
除了那个家伙正在使用app-harbor,甚至仍然没有解决方案。感谢任何帮助。