adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
608 stars 50 forks source link

No Connection to Hot-Reload Server (Port: 45820) #234

Closed itschnie closed 7 months ago

itschnie commented 7 months ago

Describe the bug When I use "dotnet-maui-reactor -f net8.0-android" and make changes to the code, I get an error message that I cannot connect to port 45820. Changes are therefore not applied.

To Reproduce Steps to reproduce the behavior:

  1. open PowerShell
  2. dotnet new install Reactor.Maui.TemplatePack
  3. dotnet tool install -g Reactor.Maui.HotReload
  4. dotnet new maui-reactor-startup -o maurec1
  5. cd .\maurec1\
  6. command "code ."
  7. open VSCode (also tried with Visual Studio 2022)
  8. execute the command: "dotnet build -t:Run -f net8.0-android"
  9. the app is created and successfully opened in the Android Simulator
  10. open another CMD shell and enter: "dotnet-maui-reactor -f net8.0-android"
  11. the following error message appears when I make changes to the code: """ Detected changes to 'Pages\MainPage.cs' Replacing syntax tree for: Pages\MainPage.cs Connection to the hot reload server (port: 45820)...Hot reload of the application not possible: System.Net.Sockets.SocketException (10061): A connection could not be established because the target computer rejected the connection. at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken) at System.Net.Sockets.TcpClient.CompleteConnectAsync(ValueTask task) at MauiReactor.HotReloadConsole.HotReloadClient.SendAssemblyFileToServer(MemoryStream stream, MemoryStream pdbStream, CancellationToken cancellationToken) in D:\a\reactorui-maui\reactorui-maui\src\MauiReactor.HotReloadConsole\HotReloadClient.cs:line 297 at MauiReactor.HotReloadConsole.HotReloadClient.ConnectionLoop(CancellationToken cancellationToken) in D:\a\reactorui-maui\reactorui-maui\src\MauiReactor.HotReloadConsole\HotReloadClient.cs:line 154 """

Expected behavior I had expected changes in the code to be applied without an error message

Additional I wonder what "D:\a\reactorui-maui\reactorui-maui\src\MauiReactor.HotReloadConsole\HotReloadClient.cs:line 297" is for a path in the error message. "D:\a\" does not exist on my local machine.

Desktop (please complete the following information):

Smartphone (please complete the following information):

adospace commented 7 months ago

Hi, MauiReactor hot reload is based on adb, can you execute the command "adb" in a shell and see what it returns? in case it says that it can't find the command you have to install it.

https://stackoverflow.com/questions/35854238/where-is-adb-exe-in-windows-10-located

https://developer-docs.magicleap.cloud/docs/guides/developer-tools/android-debug-bridge/adb-setup/#:~:text=Check%20for%20Existing%20ADB%20Installations,that%20lists%20your%20operating%20system.

https://www.xda-developers.com/install-adb-windows-macos-linux/

MoDao1990217 commented 7 months ago

嗨,MauiReactor 热重载是基于 adb 的,你能在 shell 中执行命令“adb”看看它返回什么吗?如果它说它找不到命令,你必须安装它。

https://stackoverflow.com/questions/35854238/where-is-adb-exe-in-windows-10-located

https://developer-docs.magicleap.cloud/docs/guides/developer-tools/android-debug-bridge/adb-setup/#:~:text=Check%20for%20Existing%20ADB%20Installations,that%20lists%20your%20operating%20system

https://www.xda-developers.com/install-adb-windows-macos-linux/

@adospace Hi, can it be used in production environment? I've been watching. I haven't used it yet.

itschnie commented 7 months ago

Hi, MauiReactor hot reload is based on adb, can you execute the command "adb" in a shell and see what it returns? in case it says that it can't find the command you have to install it.

https://stackoverflow.com/questions/35854238/where-is-adb-exe-in-windows-10-located

https://developer-docs.magicleap.cloud/docs/guides/developer-tools/android-debug-bridge/adb-setup/#:~:text=Check%20for%20Existing%20ADB%20Installations,that%20lists%20your%20operating%20system.

https://www.xda-developers.com/install-adb-windows-macos-linux/

I could not run the command "adb" in shell - "ABD could not be found"

So, i followed the instructions on the Stackoverflow-Link you gave me: 1a. Go to: C:\Users[user]\AppData\Local\Android\sdk\platform-tools 1b. Or Copy: %LOCALAPPDATA%\Android\sdk\platform-tools

  1. Open "environment variables"-window
  2. Copy the ADB-Path to Path
  3. Check CMD-Shell with "adb" - it worked.
  4. Started Android Emulation
  5. Open VS-Code
  6. Terminal: dotnet build -t:Run -f net8.0-android [success]
  7. On a second Terminal: dotnet-maui-reactor -f net8.0-android

Unfortunately, the same error message still appears when changes are made to the code Is there anything specific I need to consider about port: 45820? grafik

Is it possible that certain ports have to be released for the Android simulation? I've never had to do that before. The error message says: Access was denied.

I have also tried a fresh Android installation.

Unfortunately no success so far.

and sometimes only this: grafik

I dont have any problems debugging/hot reloading "normal" MAUI apps.

By the way, what does this section actually mean? Where does the path come from?

grafik

Under Visual-Studio 2022 (on the latest version) I get the following feedback when starting the program grafik

Thank you for your time! :)

adospace commented 7 months ago

Hum, I think that the problem is definitively related to adb. Let's check a few things: 1) the application should be executed in Debug mode (I think you already did it) 2) Ensure that EnableMauiReactorHotReload() is called in your program.cs (I think you already have it) 3) Ensure that you have only one emulator/device running (i.e. if the device is attached, close the emulator and vice-versa) 4) The waiting for debugger message is normal and not related to MauiReactor (you should see the same with any other .NET MAUI app) 5) Ensure you have the platform-tools installed, the adb used by MauiReactor hot-reload must be in this folder:

C:\Program Files (x86)\Android\android-sdk\platform-tools

image

image

Platform tools can be installed also from google: https://developer.android.com/tools/releases/platform-tools

or installing Android Studio

hope it helps, let me know

adospace commented 7 months ago

@MoDao1990217 sorry not sure I correctly understand what you mean, yes MauiReactor can be used in a production environment

adospace commented 7 months ago

@itschnie any news?

itschnie commented 7 months ago

@itschnie any news?

sorry for the late reply, i've been struggling a bit with illness and work.

I have downloaded the files and placed them in the folder you suggested (C:\Program Files (x86)\Android\android-sdk\platform-tools).

grafik

Unfortunately, the error persists. grafik

Android Studio is already installed. grafik

At least the hot reload works with the Windows-App. So I can work there properly :)

itschnie commented 7 months ago

Update: Maybe i solved the "Connection Problem".

I've tried:

Open Console adb kill-server adb start-server dotnet build -t:Run -f net8.0-android dotnet-maui-reactor -f net8.0-android

That was the sequence I used. I will try it again later and hope it was the solution to the problem. grafik

adospace commented 7 months ago

yes messages are correct, seems working