CreateWindowAsync ConnectionException. Cannot connect to server 'http://localhost:8000' #866

Closed
opened 2026-01-29 16:50:43 +00:00 by claunia · 6 comments
Owner

Originally created by @AlphaZeroUno on GitHub (Apr 3, 2023).

  • Version: 23.6.1
  • Target: Windows 11 Home

Hi, I have a problem running an electronic application with the latest version.
When I launch the application, I get the error in image. With the previous version 13.5.1 I didn't have this error

Steps to Reproduce:

  1. electronize build /target win
  2. Open application

image

Program.cs

using System;
using ElectronNET.API;
using ElectronNET.API.Entities;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MvcPwa.Models;
using MvcPwa.Hubs;
using Microsoft.AspNetCore.SignalR;
using NLog.Targets;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.EntityFrameworkCore;

namespace MvcPwa
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args);

        ConfigurationManager configuration = builder.Configuration; // allows both to access and to set up the config
        IWebHostEnvironment environment = builder.Environment;

        // LoginLogout
        //builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));

        //builder.Services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<AppDbContext>();

        builder.Services.ConfigureApplicationCookie(options => {
            options.Cookie.Name = ".AspNet.SharedCookie";
        });

        builder.Services.AddControllersWithViews().AddSessionStateTempDataProvider();
        builder.Services.AddRazorPages();
        builder.Services.AddSingleton<IDoStuff, DoStuff>();

        builder.Services.AddCors(o => o.AddPolicy("CorsPolicy", builder => {
            builder
            .AllowAnyMethod()
            .AllowAnyHeader()
            .AllowCredentials()
            .SetIsOriginAllowed(_ => true);
        }));

        builder.Services.AddSignalR();
        builder.Services.AddSession();
        builder.Services.AddSingleton<BaseDataAccess>();
        builder.Services.AddSingleton<BinanceProvider>();

        builder.Services.AddMvc().AddSessionStateTempDataProvider();

        var app = builder.Build();

        if (!app.Environment.IsDevelopment())
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }else
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseCors("CorsPolicy");
        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();
        app.UseSession();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<MyHub>("/hub", options =>
            {
                options.Transports =
                    HttpTransportType.WebSockets |
                    HttpTransportType.LongPolling;
            });
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();


        });

        NotificationHub.Current = app.Services.GetService<IHubContext<NotificationHub>>();

        Console.WriteLine($"port is null : {BridgeSettings.SocketPort == null}");

        if (HybridSupport.IsElectronActive)
        {
            ElectronBootstrap();
        }

        app.Run();
    }


    public static async void ElectronBootstrap()
    {
        // electronize build / target win
        WebPreferences wp = new WebPreferences();
        wp.NodeIntegration = false;

        var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
        {
            Width = 1152,
            Height = 940,
            Show = false,
            Title = "TTrade",
            WebPreferences = wp,
            Icon = System.Environment.CurrentDirectory + "\\Images\\Icon\\ttrade.ico"
        });
        browserWindow.SetTitle("A Binance tool");

        await browserWindow.WebContents.Session.ClearCacheAsync();

        // For the gracefull showing of the Electron Window when ready
        browserWindow.OnReadyToShow += () =>
        {
            //browserWindowSplash.Close();
            browserWindow.Show();
            browserWindow.Maximize();
        };
        Electron.Menu.SetApplicationMenu(new MenuItem[] { });

        browserWindow.OnClosed += () =>
        {
            Electron.App.Quit();
        };

    }

}

}

Originally created by @AlphaZeroUno on GitHub (Apr 3, 2023). <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 23.6.1 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: Windows 11 Home <!-- Enter your issue details below this comment. --> Hi, I have a problem running an electronic application with the latest version. When I launch the application, I get the error in image. With the previous version 13.5.1 I didn't have this error <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Steps to Reproduce: 1. electronize build /target win 2. Open application ![image](https://user-images.githubusercontent.com/103926446/229595804-a8087464-bf94-4ac0-9d26-c8947b7ac9fe.png) Program.cs using System; using ElectronNET.API; using ElectronNET.API.Entities; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using MvcPwa.Models; using MvcPwa.Hubs; using Microsoft.AspNetCore.SignalR; using NLog.Targets; using Microsoft.AspNetCore.Http.Connections; using Microsoft.EntityFrameworkCore; namespace MvcPwa { public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseElectron(args); ConfigurationManager configuration = builder.Configuration; // allows both to access and to set up the config IWebHostEnvironment environment = builder.Environment; // LoginLogout //builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); //builder.Services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<AppDbContext>(); builder.Services.ConfigureApplicationCookie(options => { options.Cookie.Name = ".AspNet.SharedCookie"; }); builder.Services.AddControllersWithViews().AddSessionStateTempDataProvider(); builder.Services.AddRazorPages(); builder.Services.AddSingleton<IDoStuff, DoStuff>(); builder.Services.AddCors(o => o.AddPolicy("CorsPolicy", builder => { builder .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() .SetIsOriginAllowed(_ => true); })); builder.Services.AddSignalR(); builder.Services.AddSession(); builder.Services.AddSingleton<BaseDataAccess>(); builder.Services.AddSingleton<BinanceProvider>(); builder.Services.AddMvc().AddSessionStateTempDataProvider(); var app = builder.Build(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); app.UseHsts(); }else { app.UseDeveloperExceptionPage(); } app.UseCors("CorsPolicy"); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapHub<MyHub>("/hub", options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling; }); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); NotificationHub.Current = app.Services.GetService<IHubContext<NotificationHub>>(); Console.WriteLine($"port is null : {BridgeSettings.SocketPort == null}"); if (HybridSupport.IsElectronActive) { ElectronBootstrap(); } app.Run(); } public static async void ElectronBootstrap() { // electronize build / target win WebPreferences wp = new WebPreferences(); wp.NodeIntegration = false; var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Width = 1152, Height = 940, Show = false, Title = "TTrade", WebPreferences = wp, Icon = System.Environment.CurrentDirectory + "\\Images\\Icon\\ttrade.ico" }); browserWindow.SetTitle("A Binance tool"); await browserWindow.WebContents.Session.ClearCacheAsync(); // For the gracefull showing of the Electron Window when ready browserWindow.OnReadyToShow += () => { //browserWindowSplash.Close(); browserWindow.Show(); browserWindow.Maximize(); }; Electron.Menu.SetApplicationMenu(new MenuItem[] { }); browserWindow.OnClosed += () => { Electron.App.Quit(); }; } } }
claunia added the bugmore-information-needed labels 2026-01-29 16:50:43 +00:00
Author
Owner

@FlorianRappl commented on GitHub (Apr 3, 2023):

Can you provide the MWE in a GitHub repository? Just code fragments is unfortunately not sufficient...

@FlorianRappl commented on GitHub (Apr 3, 2023): Can you provide the MWE in a GitHub repository? Just code fragments is unfortunately not sufficient...
Author
Owner

@GregorBiswanger commented on GitHub (Apr 3, 2023):

Did you also update the Electron CLI?

Then simply delete the obj/host directory from your project and try again.

@GregorBiswanger commented on GitHub (Apr 3, 2023): Did you also update the Electron CLI? Then simply delete the obj/host directory from your project and try again.
Author
Owner

@AlphaZeroUno commented on GitHub (Apr 3, 2023):

I tried to install electronNET.CLI but it is not supported by my application in NET 6.0
I tried deleting obj/host directory , but still get the same error

@AlphaZeroUno commented on GitHub (Apr 3, 2023): I tried to install electronNET.CLI but it is not supported by my application in NET 6.0 I tried deleting obj/host directory , but still get the same error
Author
Owner

@AlphaZeroUno commented on GitHub (Apr 3, 2023):

image

@AlphaZeroUno commented on GitHub (Apr 3, 2023): ![image](https://user-images.githubusercontent.com/103926446/229606647-5a2cf554-56db-4688-b445-60be124719ac.png)
Author
Owner

@FlorianRappl commented on GitHub (Apr 3, 2023):

Please follow the README. You install the CLI via dotnet tool - not as a normal NuGet package.

@FlorianRappl commented on GitHub (Apr 3, 2023): Please follow the README. You install the CLI via `dotnet tool` - not as a normal NuGet package.
Author
Owner

@AlphaZeroUno commented on GitHub (Apr 3, 2023):

I updated as said and now it works, thanks.

@AlphaZeroUno commented on GitHub (Apr 3, 2023): I updated as said and now it works, thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#866