Skip to content

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

@AlphaZeroUno

Description

@AlphaZeroUno
  • 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();
        };

    }

}

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions