【问题标题】:ReflectionTypeLoadException: Could not load types after publishing a asp.net mvc project on azureReflectionTypeLoadException:在 azure 上发布 asp.net mvc 项目后无法加载类型
【发布时间】:2018-09-20 17:21:17
【问题描述】:

所以我有这个 asp.net mvc 项目,它是从 Visual Studio 在 .NetFramework 4.7.2 下为您提供的默认模板创建的,并下载了 sensenet.service.install 和 sensenet.webpages.install 包并运行安装它们的过程。之后,我按 F5 并确认我的机器上一切正常。从那里,我决定在 azure 上发布这个项目,当网页加载时,我受到的欢迎是这个

[Exception: ReflectionTypeLoadException: Could not load types. Affected types: 
Lucene.Net.Store.RAMDirectory
Lucene.Net.Search.FieldDoc
Lucene.Net.Search.NumericRangeQuery
Lucene.Net.Search.SortField
Lucene.Net.Index.Term
First message: Type 'Lucene.Net.Store.RAMDirectory' in assembly 'Lucene.Net, Version=2.9.4.301, Culture=neutral, PublicKeyToken=null' has method 'OnDeserialized' with an incorrect signature for the serialization attribute that it is decorated with.]
   SenseNet.Services.SenseNetGlobal.get_Instance() in E:\BuildAgent\_work\63\s\src\Services\SenseNetGlobal.cs:74
   SenseNet.Portal.Global.Application_Start(Object sender, EventArgs e) in E:\BuildAgent\_work\63\s\src\Services\Global.cs:15

[HttpException (0x80004005): ReflectionTypeLoadException: Could not load types. Affected types: 
Lucene.Net.Store.RAMDirectory
Lucene.Net.Search.FieldDoc
Lucene.Net.Search.NumericRangeQuery
Lucene.Net.Search.SortField
Lucene.Net.Index.Term
First message: Type 'Lucene.Net.Store.RAMDirectory' in assembly 'Lucene.Net, Version=2.9.4.301, Culture=neutral, PublicKeyToken=null' has method 'OnDeserialized' with an incorrect signature for the serialization attribute that it is decorated with.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +10062153
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): ReflectionTypeLoadException: Could not load types. Affected types: 
Lucene.Net.Store.RAMDirectory
Lucene.Net.Search.FieldDoc
Lucene.Net.Search.NumericRangeQuery
Lucene.Net.Search.SortField
Lucene.Net.Index.Term
First message: Type 'Lucene.Net.Store.RAMDirectory' in assembly 'Lucene.Net, Version=2.9.4.301, Culture=neutral, PublicKeyToken=null' has method 'OnDeserialized' with an incorrect signature for the serialization attribute that it is decorated with.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10043444
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

在这个 github 问题 https://github.com/dotnet/standard/issues/300 中有一条评论说这已在 .NetFramework 4.7.2 中得到修复,但对我来说似乎并非如此。

所以我的问题是,为什么我在本地运行这个项目而不是在 azure 上发布它时没有发生这个异常?

【问题讨论】:

    标签: c# asp.net-mvc azure reflection sensenet


    【解决方案1】:

    假设这与 .Net Framework 中的修复有关,您是正确的。正如您发现的二进制序列化/类型转发问题所暗示的那样,它发生在 4.7.2 中。

    (有关将 sensenet 迁移到 .Net Standard 的更多详细信息,请参阅 here

    我们在 Azure 测试环境中遇到了同样的问题,原因是 4.7.2 尚未部署到 Azure 应用服务(或至少没有部署到所有地方)。最初的计划是在 2018 年 9 月进行,但根据this issue,他们将其推迟到了 10 月。

    这不是我们能控制的,所以解决办法是

    等待微软将 4.7.2 部署到应用服务

    要检查您的 Azure 环境中支持的 .Net Framework,请查看this article

    关于将 sensenet 部署到应用服务

    您所尝试的(将 sn 部署到 Azure)在技术上是可行的,您需要的一切都已发布,但还没有详细的指南。不过我们正在努力。

    简而言之:

    1. 将数据库(很可能通过备份/恢复)部署到 Azure SQL Server。
    2. 配置消息传递,因为您的应用实例必须相互通信。在本地环境中,我们通常使用 MSMQ,但这在云中不可用,因此我们为 sensenet 提供了RabbitMQ messaging provider
    3. 索引:这更复杂,因为您必须为centralized search service 启动一个虚拟机并在那里安装服务。

    我们的计划是让所有这一切在未来变得更容易和更直接,但感谢你开创了一些新的东西:)。

    【讨论】:

    • 是否有其他部署服务比 azure 更易于使用和配置?也许aws s3?还是它们都需要相同的步骤?不过感谢您提供如此详细的答案。
    猜你喜欢
    • 2023-03-07
    • 2017-05-16
    • 2021-06-26
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    相关资源
    最近更新 更多