Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in TransformBlocks #1310

Closed
mikaellindemann opened this issue Aug 19, 2020 · 7 comments
Closed

NullReferenceException in TransformBlocks #1310

mikaellindemann opened this issue Aug 19, 2020 · 7 comments
Assignees

Comments

@mikaellindemann
Copy link
Contributor

After upgrading my setup using PostgreSQL from 8.3 (latest packages) to 8.4 I get the following exceptions:

When opening a page in the manager:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Piranha.Services.ContentService`3.TransformBlocks(IEnumerable`1 blocks)
   at Piranha.Repositories.PageRepository.ProcessAsync[T](Page page, T model)
   at Piranha.Services.ContentService`3.TransformAsync[T](TContent content, ContentTypeBase type, Func`3 process)
   at Piranha.Repositories.PageRepository.GetById[T](Guid id)
   at Piranha.Services.PageService.GetByIdAsync[T](Guid id)
   at Piranha.Manager.Services.PageService.GetById(Guid id, Boolean useDraft)
   at Piranha.Manager.Controllers.PageApiController.Get(Guid id)
   at lambda_method(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Piranha.AspNetCore.SitemapMiddleware.Invoke(HttpContext context, IApi api, IApplicationService service)
   at Piranha.AspNetCore.IntegratedMiddleware.Invoke(HttpContext context, IApi api, IApplicationService service)
   at Piranha.AspNetCore.Security.SecurityMiddleware.InvokeAsync(HttpContext ctx, IApplicationService service)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

When opening the same page from the frontend

System.NullReferenceException: Object reference not set to an instance of an object.
   at Piranha.Services.ContentService`3.TransformBlocks(IEnumerable`1 blocks)
   at Piranha.Repositories.PageRepository.ProcessAsync[T](Page page, T model)
   at Piranha.Services.ContentService`3.TransformAsync[T](TContent content, ContentTypeBase type, Func`3 process)
   at Piranha.Repositories.PageRepository.GetStartpage[T](Guid siteId)
   at Piranha.Services.PageService.GetStartpageAsync[T](Nullable`1 siteId)
   at Piranha.AspNetCore.IntegratedMiddleware.Invoke(HttpContext context, IApi api, IApplicationService service)
   at Piranha.AspNetCore.Security.SecurityMiddleware.InvokeAsync(HttpContext ctx, IApplicationService service)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
@honzajscz
Copy link

Same here. I recreated the db and it works. But I have no data in it

@tidyui
Copy link
Member

tidyui commented Aug 19, 2020

@honzajscz So you get the error when upgrading a database but not when creating a new one?

@tidyui
Copy link
Member

tidyui commented Aug 19, 2020

I have located the error. The image aspect field that was added in the ImageBlock in version 8.3 gets it's CLRType stored like this in the database:

Piranha.Extend.Fields.SelectField`1[[Piranha.Extend.Blocks.ImageAspect, Piranha, Version=8.3.0.0, Culture=neutral, PublicKeyToken=null]]

This obviously creates issues when upgrading to version 8.4.0.0 as the assembly version won't match. This is not how we store types in general but seems to rather be how .NET evaluates generic types, something that we missed during the development of 8.3.

Solution

We will try to see how we can bypass this issue at the moment, however until we release a hotfix for this the temporary solution would be to open your database, do a select query for all BlockFields where 'CLRType' LIKE '%Version=8.3.0.0%' and change 8.3.0.0 to 8.4.0.0.

Regards

@tidyui tidyui added this to the Version 8.4 SR1 milestone Aug 19, 2020
@tidyui tidyui closed this as completed in 09cb3bc Aug 19, 2020
tidyui added a commit that referenced this issue Aug 19, 2020
@tidyui tidyui changed the title 8.4: NullReferenceException in ContentService3.TransformBlocks(IEnumerable1) NullReferenceException in ContentService.TransformBlocks Aug 19, 2020
@tidyui tidyui changed the title NullReferenceException in ContentService.TransformBlocks NullReferenceException in TransformBlocks Aug 19, 2020
@tidyui tidyui self-assigned this Aug 19, 2020
@tidyui
Copy link
Member

tidyui commented Aug 19, 2020

Version 8.4.1 of Piranha is now available on NuGet

@tidyui
Copy link
Member

tidyui commented Aug 19, 2020

@mikaellindemann @honzajscz Thanks for the quick feedback on the issue!

@tidyui
Copy link
Member

tidyui commented Aug 20, 2020

As a final test I've now also upgraded our official homepage to the latest version without issues!

@mikaellindemann
Copy link
Contributor Author

I have also upgraded mine and the pages are now loading again :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants