简体   繁体   中英

ReflectionTypeLoadException: Could not load types after publishing a asp.net mvc project on azure

So I have this asp.net mvc project that was created from the default template that visual studio provides you with under .NetFramework 4.7.2 and downloaded both the sensenet.service.install and sensenet.webpages.install package and ran through the process of installing them. After that, I pressed F5 and confirmed that everything was working fine on my machine. From there, I decided to publish this project on azure and what I was greeted with was this when the webpage loaded

[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

There was a comment in this github issue https://github.com/dotnet/standard/issues/300 that said that this was fixed in .NetFramework 4.7.2 but this does not seem to be the case for me.

So my question is, why did this exception not occurred when I ran this project locally versus publishing it on azure?

you are correct assuming that this is related to that fix in .Net Framework. It happened in 4.7.2 as the binary serialization / type forwarding issue you have found suggests.

(more details on moving sensenet to .Net Standard can be found here )

We face the same issue in our Azure test environment and the reason is that 4.7.2 is not yet deployed to Azure App Service (or at least not everywhere). The original plan was for this to happen in September 2018 but they pushed it to October according to this issue .

This is not something we can control, so the solution is to

wait for Microsoft to deploy 4.7.2 to App Service

To check for the supported .Net Framework on your Azure environment please check this article .

About deploying sensenet to App Service

What you have tried (deploying sn to Azure) is technically possible, everything you need is already published but there is no detailed guideline for that yet. We are working on it though.

In a super-small nutshell:

  1. deploy the db (most likely by backup/restore) to Azure SQL Server.
  2. configure messaging, because your app instances have to communicate with each other. In an on-premise environment we usually use MSMQ, but that is not available in the cloud, so we offer a RabbitMQ messaging provider for sensenet.
  3. indexing: this is more complicated, because you'll have to spin up a VM for a centralized search service and install the service there.

The plan is that all this will be made easier and more straightforward in the future, but thanks for pioneering something new :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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