No database provider has been configured for this DbContext Error

Hello radzen team,
when i try to open a page in RBS 1.0.6 this error is thrown:

System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, DbContextOptions contextOptions, DbContext context)
   at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker()
   at Trent.TrentdbService.Reset()
   at Trent.Services.TrentService.ResetContext()
   at Trent.Services.TrentService..ctor(SessionService sessionService, ParameterService parameterService, KonstantenService konstantenService, BrowserService browserService, ExceptionService exceptionService, SecurityService securityService, TrentdbService trentdbService, GlobalsService globalsService, TrentNavigationService trentNavigationService, MessagesService messagesService)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.InvokeWithManyArguments(RuntimeConstructorInfo ci, Int32 argCount, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass7_0.<CreateInitializer>g__Initialize|1(IServiceProvider serviceProvider, IComponent component)
   at Microsoft.AspNetCore.Components.ComponentFactory.PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance)
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame& frame, Int32 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
   at Radzen.Server.RemoteRenderer.HandleException(Exception exception) 
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
   at Radzen.Server.Router.Render(Type layout, Type component) 
   at Radzen.Server.Router.OnRouteChanged(Object sender, RouteChangedEventArgs e) 
   at Radzen.Server.RouterService.Route(Type component, Type defaultLayout) 
   at Radzen.Server.CircuitHost.AddComponent(Type layout, Type page) 
   at Radzen.Server.ProjectServer.Render(String fileName, String source) 
   at Radzen.Server.ProgramController.Render(RenderRequest request) 

When i click on the "Data" button in the left upper corner RBS cannot find the database connection and it runs froever searching it:

My project is the same as i send you at info@radzen.com. No changes made til then.
With RBS 1.0.5 i was able to open most pages (not all). In RBS 1.0.6 the "connection" error is shown on all pages.

Hope you can help
Thomas

This stacktrace looks as if you have a service that tries to reset a database in its constructor. That's is going be executed in design time and I don't think you want it :slight_smile: RBS excludes DB access and initialization code on purpose to prevent unwanted DB queries and information loss. However it doesn't cover custom services.You can check here for tips how to exclude code from Radzen Blazor Studio's design time build. For example you can try wrapping the DB reset code from the constructor of that service.

We never managed to open your project as it contains third party assemblies that are not available on nuget.org.

Hi @korchev,
i will try to exclude the devexpress packages and send the project to you without the devexpress dependencies but its not so easy :laughing:

i dont really know what you mean with resetting database in constructor. this part is done from an external programmer in the beginning of the project 2 years ago and changed never til then.
But i will try to find out what happens there.

first i send you the project as soon as i eleminate the devexpress dependencies.

thank you!
Thomas

I know :slight_smile: I tried this myself and failed. I also tried to trial the third party so I can get access to their private nuget repository and also failed.

If you see the exception stacktrace you will notice this:

at Trent.TrentdbService.Reset()
at Trent.Services.TrentService.ResetContext()
at Trent.Services.TrentService..ctor

It means that the constructor of the TrentService service calls the Reset method of the TrendbService. You may want to revisit that logic as it seems erroneous to me - constructors should not perform DB access IMHO.