Application does start with net5.0 with low level or unmanaged c# libraries #701

Closed
opened 2026-01-29 16:46:16 +00:00 by claunia · 1 comment
Owner

Originally created by @aboccag on GitHub (Sep 18, 2021).

Originally assigned to: @GregorBiswanger on GitHub.

Hi there!

  • Version: 13.5.1
  • Target: net5.0

Steps to Reproduce:

I would like to run a simple app where I want to instantiate a Basler camera (emulation for now). To do that, I just have to import the library and do a simple Camera camera = new Camera();

My netcore app has been created with the microsoft new project with react and redux, then I add electron.net api and I started the electronize init / start command

Here is the service I registered with the classic microsoft DI :

using System;
using Basler.Pylon;
using ElectronNET.API;
using Microsoft.Extensions.Logging;

    public class CameraService : ICameraService
    {
        private readonly ILogger<CameraService> _logger;

        public CameraService(ILogger<CameraService> logger)
        {
            _logger = logger;
            Camera c = new Camera();
            _logger.LogInformation(c.ToString());
            
            Electron.IpcMain.On("cam", async args =>
            {
                try
                {
                    Camera c = new Camera();
                    _logger.LogInformation(c.ToString());
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message);
                }
            });
        }
    }

Here are the different behaviors I have with different situations:

Situation 1 - simple console app with net 5.0 : -> working because I can access the object and Emulation (0815-0000) and open the camera

info: akatech.ui.electron.Services.CameraService[0]
      Emulation (0815-0000)

situation 2 - run this application with visual studio debug/run : -> working because I can access the object and Emulation (0815-0000) and open the camera

info: akatech.ui.electron.Services.CameraService[0]
      Emulation (0815-0000)
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Dev\Projects\Akatech\akatech.ui.electron\akatech.ui.electron

Situation 3 - When I run the application with electronize start command

it stops here and nothing happen, no errors, no messages, waiting indefinitely


Electron Socket IO Port: 8009
Electron Socket started on port 8009 at 127.0.0.1
ASP.NET Core Port: 8010
stdout: Use Electron Port: 8009

Situation 4 - When I remove the first Camera camera = new Camera() before the Electron.IpcMain.On in order try to create the camera after the application is completely started


    public class CameraService : ICameraService
    {
        private readonly ILogger<CameraService> _logger;

        public CameraService(ILogger<CameraService> logger)
        {
            _logger = logger;
            //Camera c = new Camera();
            //_logger.LogInformation(c.ToString());
            
            Electron.IpcMain.On("cam", async args =>
            {
                try
                {
                    Camera c = new Camera();
                    _logger.LogInformation(c.ToString());
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message);
                }
            });
        }
    }

When the event is triggered by the frontend with

electron.ipcRenderer.send('cam', "info")

I got just an error Got disconnected! Reason: transport close


Electron Socket IO Port: 8010
Electron Socket started on port 8010 at 127.0.0.1
ASP.NET Core Port: 8011
stdout: Use Electron Port: 8010
stdout: ASP.NET Core host has fully started.
stdout: info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:8011
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Dev\Projects\Akatech\akatech.ui.electron\obj\Host\bin
ASP.NET Core Application connected... global.electronsocket KF4Hi45LKbloPX_VAAAA 2021-09-18T10:32:28.540Z
stdout: BridgeConnector connected!
(node:21916) electron: The default of contextIsolation is deprecated and will be changing from false to true in a future release of Electron.  See https://github.com/electron/electron/issues/23506 for more information
stdout: warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.
Got disconnect! Reason: transport close

I tried to add a breakpoint before the new camera in the IPC (situation 4) with the attatch process feature.
I got this exception but I don't now if it is correlated
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

image

situation 5 :
I did also clone the https://github.com/ElectronNET/electron.net-musicplayer-sample sample which is netcore3.1 and Electron.net api 5.30.1 and everything is working (IPC event create camera and create camera at the class instanciation)
I also noticed that this sample with the same api 5.30.1 with netcore5 instead of netcore3.1 also does not work (same behavior as the situation 3 and 4)

We really do want to use netcore5 as well as the latest versions of your library that is very promising!

I really hope someone could help us ! 👍

Originally created by @aboccag on GitHub (Sep 18, 2021). Originally assigned to: @GregorBiswanger on GitHub. Hi there! <!-- 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**: 13.5.1 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: net5.0 <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Steps to Reproduce: I would like to run a simple app where I want to instantiate a Basler camera (emulation for now). To do that, I just have to import the library and do a simple Camera camera = new Camera(); My netcore app has been created with the microsoft new project with react and redux, then I add electron.net api and I started the electronize init / start command Here is the service I registered with the classic microsoft DI : ```c# using System; using Basler.Pylon; using ElectronNET.API; using Microsoft.Extensions.Logging; public class CameraService : ICameraService { private readonly ILogger<CameraService> _logger; public CameraService(ILogger<CameraService> logger) { _logger = logger; Camera c = new Camera(); _logger.LogInformation(c.ToString()); Electron.IpcMain.On("cam", async args => { try { Camera c = new Camera(); _logger.LogInformation(c.ToString()); } catch (Exception e) { _logger.LogError(e.Message); } }); } } ``` Here are the different behaviors I have with different situations: Situation 1 - simple console app with net 5.0 : -> working because I can access the object and Emulation (0815-0000) and open the camera ```bash info: akatech.ui.electron.Services.CameraService[0] Emulation (0815-0000) ``` situation 2 - run this application with visual studio debug/run : -> working because I can access the object and Emulation (0815-0000) and open the camera ```bash info: akatech.ui.electron.Services.CameraService[0] Emulation (0815-0000) info: Microsoft.Hosting.Lifetime[0] Now listening on: https://localhost:5001 info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:5000 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\Dev\Projects\Akatech\akatech.ui.electron\akatech.ui.electron ``` Situation 3 - When I run the application with electronize start command **it stops here and nothing happen, no errors, no messages, waiting indefinitely** ```bash Electron Socket IO Port: 8009 Electron Socket started on port 8009 at 127.0.0.1 ASP.NET Core Port: 8010 stdout: Use Electron Port: 8009 ``` Situation 4 - When I remove the first Camera camera = new Camera() before the Electron.IpcMain.On in order try to create the camera after the application is completely started ```c# public class CameraService : ICameraService { private readonly ILogger<CameraService> _logger; public CameraService(ILogger<CameraService> logger) { _logger = logger; //Camera c = new Camera(); //_logger.LogInformation(c.ToString()); Electron.IpcMain.On("cam", async args => { try { Camera c = new Camera(); _logger.LogInformation(c.ToString()); } catch (Exception e) { _logger.LogError(e.Message); } }); } } ``` When the event is triggered by the frontend with ```javascript electron.ipcRenderer.send('cam', "info") ``` I got just an error Got disconnected! Reason: transport close ```bash Electron Socket IO Port: 8010 Electron Socket started on port 8010 at 127.0.0.1 ASP.NET Core Port: 8011 stdout: Use Electron Port: 8010 stdout: ASP.NET Core host has fully started. stdout: info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:8011 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: C:\Dev\Projects\Akatech\akatech.ui.electron\obj\Host\bin ASP.NET Core Application connected... global.electronsocket KF4Hi45LKbloPX_VAAAA 2021-09-18T10:32:28.540Z stdout: BridgeConnector connected! (node:21916) electron: The default of contextIsolation is deprecated and will be changing from false to true in a future release of Electron. See https://github.com/electron/electron/issues/23506 for more information stdout: warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect. Got disconnect! Reason: transport close ``` I tried to add a breakpoint before the new camera in the IPC (situation 4) with the attatch process feature. I got this exception but I don't now if it is correlated System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. ![image](https://user-images.githubusercontent.com/57749489/133885946-c6ee04a7-5bff-4ee1-8939-dd53025f2015.png) situation 5 : I did also clone the https://github.com/ElectronNET/electron.net-musicplayer-sample sample which is netcore3.1 and Electron.net api 5.30.1 and everything is working (IPC event create camera and create camera at the class instanciation) I also noticed that this sample with the same api 5.30.1 with netcore5 instead of netcore3.1 also does not work (same behavior as the situation 3 and 4) We really do want to use netcore5 as well as the latest versions of your library that is very promising! I really hope someone could help us ! 👍
claunia added the bug label 2026-01-29 16:46:16 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Mar 28, 2023):

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

@GregorBiswanger commented on GitHub (Mar 28, 2023): 🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉 With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#701