Daddoon / BlazorMobile

Create full C# driven hybrid-apps for iOS, Android, UWP & Desktop with Blazor!
MIT License
413 stars 55 forks source link

Error when running the Electron Desktop app #195

Closed Daddoon closed 4 years ago

Daddoon commented 4 years ago

This issue is created from a review received by mail

What we had to do to get Electron Desktop working

1) We received the error below when running the Electron Desktop app

Error in the Windows App Event Log Description: A .NET Core application failed. Application: BlazorMobile.Sample.Desktop.exe Path: C:\workspace\blazormobile\src\BlazorMobile.Templates\content\BlazorMobile.Sample\BlazorMobile.Sample.Desktop\obj\Host\bin\BlazorMobile.Sample.Desktop.exe Message: Error: An assembly specified in the application dependencies manifest (BlazorMobile.Sample.Desktop.deps.json) was not found: package: 'BlazorMobile.Common', version: '3.2.4-preview2.20160.5' path: 'lib/netstandard2.0/BlazorMobile.Common.dll'

How We Fixed Copy the dll’s below to "NOOB.Wallet.Podium.Desktop/obj/Host/bin"

BlazorMobile.Common.dll BlazorMobile.Web.dll Microsoft.AspNetCore.Blazor.HttpClient.dll Microsoft.AspNetCore.Components.WebAssembly.dll Microsoft.AspNetCore.Components.WebAssembly.Server.dll Microsoft.JSInterop.WebAssembly.dll Newtonsoft.Json.dll NOOB.Wallet.Podium.Common.dll (or BlazorMobile.Sample.Common.dll)

2) In the electron desktop app had to apply a fix for an issue with port 8888

a) Goto project NOOB.Wallet.Podium.Desktop or BlazorMobile.Sample.Desktop b) Edit Startup.cs -> find "app.UseBlazorMobileWithElectronNET(useWASM)” and add "WebApplicationFactory.SetHttpPort(8882);" above "app.UseBlazorMobileWithElectronNET(useWASM)"

the new file should look like the rows of data below WebApplicationFactory.SetHttpPort(8882); app.UseBlazorMobileWithElectronNET(useWASM);

3) Goto project NOOB.Wallet.Podium or BlazorMobile.Sample and goto App.xml code( App.xml.cs) edit the port number i.g WebApplicationFactory.SetHttpPort(8881);


Question: Why did we put WebApplicationFactory.SetHttpPort(8882); above to app.UseBlazorMobileWithElectronNET(useWASM); Answer: We did so to override the port. it was not overriding when “iselectron” is set to “true”

Daddoon commented 4 years ago

My answer

The BlazorMobile project doesn’t have yet automatized tests and builds, so i may miss potential regressions.

  1. It’s pretty strange that BlazorMobile.Common.dll was not found in the template, as it should be declared as a dependency in BlazorMobile.ElectronNET. I will double check this, or if it’s something like a missing attribute for including some dll, I don’t know yet.

I will open an issue on Github with some of theses issue for tracking purpose.

  1. Just to be clear, the WebApplicationFactory.SetHttpPort(8882) method call on Desktop, is mandatory ONLY if you use the WASM implementation of Blazor, in order to use some of BlazorMobile API that allow to switch current loaded app or remote load another app, like specified in the doc. If you use the .NET Core (not WASM), you don’t have to call this method (or at least it will be a no-op) as it will use ASP.NET Core implementation, instead of EmbedIO server, used for mobile devices too. Also you can put breakpoint and debug the non-wasm version on Desktop (at least by attaching the debugger to the app when the Electron app launched !).

But beware, WebApplicationFactory.SetHttpPort was already called on your Desktop app indrectly. In fact, it is called in the shared Xamarin project, the common one used also for BlazorMobile for Android/iOS/UWP. The call should be done in the project with the shortest name, meaning if working directly on the source code, in the BlazorMobile.Sample project, in the file App.xaml.cs.

In my opinion, it is better to remove your line, and only modify the one in the shared project, as the change will be reflected on all platform implementations directly. Note also that if the call to this method is not made, or if the port is unavailable, it will default to 8888 (if not called) or at least to the first available port. So you don’t have to worry about port when releasing the app, it’s meaningful mainly when debugging.

  1. Well, by reading your last answer, I see that you already found the file to modify on the shared project. Except your port 8888 issue, I’m wondering, why did you have to call this method twice, one from the Desktop project, and one from the shared project ?

  2. Well I’m late here haha, you answered the previous point. IsElectron, true or false, should not influence the port used (at least it’s not something managed by BlazorMobile).

The useWASM option should influence.

If you set it to false, you have to override the pure ASP.NET Core port used in Program.cs from the Desktop project, as it use Kestrel server. If you set it to true, you have to override from WebApplicationFactory.SetHttpPort (called in the shared project) as it will overload the port used in BlazorMobile with the EmbedIO server.

Please correct me if I understood something wrong.

Daddoon commented 4 years ago

I reproduced the error locally , trying to fix that !

Daddoon commented 4 years ago

I don't know yet if this is a bug or a regression from me or from .NET Core / Visual Studio.

Actually, it seem that some project DLL are not generated when publishing the project if we are in Debug configuration. However everything seem to be fine (in term of generation) when building in release mode.

Investigating.

Daddoon commented 4 years ago

It seem that all the missing dependencies are all the transitives dependencies from NuGet packages.

The publish event look fine in bin folder, but there is some missing content when seeing the obj folder about the temporary published files.

ElectronNET is maybe relying on that, i must investigate how it is published and fetched for the ElectronNET deploy.

Daddoon commented 4 years ago

This issue appear in BlazorMobile 3.2.3 but not in BlazorMobile 3.2.2.

BlazorMobile 3.2.3 use the new Blazor publishing format, but as it was related to WASM, i don't know if this is for this reason.

Daddoon commented 4 years ago

I'm not totally sure, but it seem this bug occur since the Blazor publish workflow has change from Microsoft side. I don't know why, but the integrated publish event seem to forget transitives dependencies from the Blazor project referenced from Desktop.

I created a NuGet package for the next version called BlazorMobile.Build.ElectronNET that workaround this issue in the publishing event.

It should work out of the box in the next release.

Daddoon commented 4 years ago

Closing as it will be available in next release.

Daddoon commented 4 years ago

A Fix has been released: https://github.com/Daddoon/BlazorMobile/blob/master/MIGRATION.md#blazormobile-324-preview2201605-to-325-preview3201683