OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.35k stars 2.37k forks source link

New MultiTenant project throws NullReferenceException after setup #5079

Open Craige opened 4 years ago

Craige commented 4 years ago

Immediately after setup of a MultiTenant default project (no secondary tenants created yet), OrchardCore throws a NullReferenceException.

dbug: OrchardCore.Data.Migration.AutomaticDataMigrations[0]
      Executing data migrations
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at YesSql.QueryExtensions.Query[T](ISession session)
   at OrchardCore.Data.Migration.DataMigrationManager.GetDataMigrationRecordAsync() in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Data\Migration\DataMigrationManager.cs:line 62
   at OrchardCore.Data.Migration.DataMigrationManager.GetFeaturesThatNeedUpdateAsync() in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Data\Migration\DataMigrationManager.cs:line 76
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAllFeaturesAsync() in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Data\Migration\DataMigrationManager.cs:line 365
   at OrchardCore.Environment.Shell.Scope.ShellScope.ActivateShellAsync() in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 196
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 152
   at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 59
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
deanmarcussen commented 4 years ago

can you advise which database you are using here? i.e. MSSQL or MySQL.

Also version of OC?

Craige commented 4 years ago

SQLite

OC 1.0.0-rc1-11143

dotnet core 3.1

Will try to reproduce again. Noticed after this that I can't get any project setup since spooling up a new rc-1 project, so this may be symptomatic of something a bit deeper.

deanmarcussen commented 4 years ago

spoke with @Craige about this on gitter, believe it is resolved (issues where because the main startup was calling services they shouldn't, i.e. services.AddMvc()).

kevinchalet commented 3 years ago

Reopening: the same issue occurs when you go with services.AddOrchardCore() and forget to configure the database provider (e.g with "DatabaseProvider": "Sqlite" in appsettings.json). Not the pleasant error message you'd expect 😄

DrewBrasher commented 3 years ago

I was not able to reproduce this but maybe don't understand the conditions that cause it. Here are the steps I took:

  1. Cloned the dev branch
  2. Made sure no DatabaseProvider was set in the appsettings.json file
  3. Ran the OrhchardCore.Cms.Web project
  4. Used the "Software as a Service" recipe and selected "Sqlite" as the database (there is no way to not select a database here)

The setup finished without any error.

sebastienros commented 3 years ago

Apparently it when a site doesn't use the Setup module, it needs a database provider to be set, or it crashes.