# DialogService does not work from Electron.Net

**URL:** <https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099>\
**Category:** Blazor Server\
**Created:** [November 28, 2019, 9:16pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099 "2019-11-28T21:16:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 28, 2019, 9:16pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/1 "2019-11-28T21:16:32Z")

</div>

I'm using a server-side Blazor in an Electron.Net app. I created an application menu in a C# class with an on-click event to open a dialog and it does not work. I suspect the problem is the scope of the injected DialogService and the dependency on the NavigationManager. When using the DialogService in a Blazor page, it works, but not from my standard C# class.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 5:59am UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/2 "2019-11-29T05:59:06Z")

</div>

Hi @NmsPLavoie,

Welcome to the Radzen community!

To be honest we haven't tested with Electron.NET. You are probably right and some service may not be provided. Is there any stacktrace available? By the way did you add a `<RadzenDialog />` to your layout similar to [this](https://github.com/akorchev/blazor.radzen.com/blob/master/Shared/MainLayout.razor#L12)?

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 2:09pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/3 "2019-11-29T14:09:08Z")

</div>

No stacktrace because no error, it just does nothing. Yes, I have the RadzenDialog and I confirm it works by using the DialogService directly in a Blazor page.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 3:23pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/4 "2019-11-29T15:23:31Z")

</div>

Tried it with our online demos. The dialog page didn't work initially because SQLIte failed to initialize. However after removing all DB related code it worked as expected.

 ![image](https://forum.radzen.com/uploads/default/original/2X/9/9c50cf9c7f8eb8b1938ffdd6b30e1204ca7bbf28.png)

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 3:35pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/5 "2019-11-29T15:35:52Z")

</div>

Thank you for the quick reply. If used directly in a Blazor page, it works. But if you try to call it from the ApplicationMenu, it doesn't.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 3:39pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/6 "2019-11-29T15:39:48Z")

</div>

Unfortunately I am not sure how to test that.

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 3:54pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/7 "2019-11-29T15:54:25Z")

</div>

In Setup.Configure(), add :

```
  Electron.Menu.SetApplicationMenu(new[]
                                     {
                                       new MenuItem
                                         {
                                           Label = "DialogService",
                                           Submenu = new[]
                                                       {
                                                         new MenuItem
                                                           {
                                                             Label = "Test",
                                                             Click = () => DialogService.Open<TestPage>("Test")
                                                           }
                                                       }
                                         }
                                     });
```

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 3:59pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/8 "2019-11-29T15:59:43Z")

</div>

Where is the DialogService coming from? Is it the same instance as the one injected? You may have to get it at runtime from the service collection.

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 4:06pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/9 "2019-11-29T16:06:29Z")

</div>

I don't know how to get a proper instance of the DialogService. When I try to get it from DI within Setup.Configure(), I'm receiving an error. I tried new DialogService() or differ the DI later on the app lifecycle with no error, but nothing happens. I tried to configure it with AddSingleton or AddScoped, even created a scope before DI it, but nothing works.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 4:52pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/10 "2019-11-29T16:52:55Z")

</div>

I tried the code you provided but it doesn't seem to execute no matter what is in the Click handler. Tried with `await Electron.Dialog.ShowMessageBoxAsync("Test");` and it didn't show.

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 5:01pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/11 "2019-11-29T17:01:10Z")

</div>

`Electron.Dialog.ShowMessageBoxAsync("Test")` works for me in the AppMenu. I'm on Windows, so I'm not sure how is supposed to work on MacOS.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 5:09pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/12 "2019-11-29T17:09:07Z")

</div>

Throwing an exception doesn't work for me either. Anyway my idea is that you need to get an instance of the DialogService which is the same as the one provided in the Blazor application. I wanted to try with:

`var dialogService = app.ApplicationServices.GetService<DialogService>();` but couldn't because no code was executed when I clicked the menu item.

Instantiating a new service won't work for sure. It has to be the one provided to the Blazor app.

A possible workaround would be to try the IPC - the Blazor app will listen to an event sent on menu click and invoke the DialogService.

---

<div class="post-metadata">

**Author:** ![NmsPLavoie](https://forum.radzen.com/user_avatar/forum.radzen.com/nmsplavoie/32/2100_2.png) [@NmsPLavoie](https://forum.radzen.com/u/NmsPLavoie)\
**Post date:** [November 29, 2019, 5:36pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/13 "2019-11-29T17:36:23Z")

</div>

I reproduced the problem with the LatestBlazor project : [https://send.firefox.com/download/de91a9c8f8e8e8c5/#kcbTowajLz8YovtfGToPVQ](https://send.firefox.com/download/de91a9c8f8e8e8c5/#kcbTowajLz8YovtfGToPVQ)

Injecting DialogService dialogService into Startup.Configure trigger that exception :

```
  Application startup exception

```

System.Exception: Could not resolve a service of type 'Radzen.DialogService' for the parameter 'dialogService' of method 'Configure' on type 'LatestBlazor.Startup'.  
---\> System.InvalidOperationException: 'RemoteNavigationManager' has not been initialized.  
at Microsoft.AspNetCore.Components.NavigationManager.AssertInitialized()  
at Microsoft.AspNetCore.Components.NavigationManager.add\_LocationChanged(EventHandler`1 value) at Radzen.DialogService..ctor(NavigationManager uriHelper) at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 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.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)  
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)  
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, 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\_\_DisplayClass1\_0.b\_\_0(ServiceProviderEngineScope scope)  
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)  
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)  
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)  
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)  
--- End of inner exception stack trace ---  
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)  
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.\<\>c\_\_DisplayClass4\_0.b\_\_0(IApplicationBuilder builder)  
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.\<\>c\_\_DisplayClass13\_0.b\_\_2(IApplicationBuilder app)  
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.\<\>c\_\_DisplayClass0\_0.g\_\_MiddlewareFilterBuilder|0(IApplicationBuilder builder)  
at Microsoft.AspNetCore.HostFilteringStartupFilter.\<\>c\_\_DisplayClass0\_0.b\_\_0(IApplicationBuilder app)  
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 29, 2019, 6:00pm UTC](https://forum.radzen.com/t/dialogservice-does-not-work-from-electron-net/2099/14 "2019-11-29T18:00:53Z")

</div>

Unfortunately I've hit this one before: [https://github.com/aspnet/AspNetCore/issues/13906](https://github.com/aspnet/AspNetCore/issues/13906). No solution provided - scopes are different. I am out of ideas but to use Electron IPC and open the dialog from Blazor (where it works) after receiving a message from the menu click.
