JaneySprings / DotNet.Meteor

A VSCode extension that can run and debug .NET apps (Xamarin, MAUI, Avalonia)
https://marketplace.visualstudio.com/items?itemName=nromanov.dotnet-meteor
MIT License
269 stars 10 forks source link

Continuous crashing when hot reloading in android tablet #111

Closed abelgarciasaiz closed 2 months ago

abelgarciasaiz commented 2 months ago

Hi

I am running .Net Meteor in an android tablet but the application crashes continuously. The same in android phone or iOS works perfectly.

Android 12 .Net 8.0.6 Device Lenovo tab Pro Plus

I attach the full stack trace

System.ArgumentNullException: Value cannot be null. (Parameter 'json') File "ThrowHelper.cs", line 13, in void ThrowHelper.ThrowArgumentNullException(string parameterName) throw new ArgumentNullException(parameterName); File "JsonSerializer.Read.String.cs", line 207, in TransferObject JsonSerializer.Deserialize(string json, JsonTypeInfo jsonTypeInfo) ThrowHelper.ThrowArgumentNullException(nameof(json)); File "/Users/nromanov/Flow/DotNet.Meteor/src/DotNet.Meteor.HotReload.Plugin/Server.cs", line 36, col 13, in async void Server.Initialize(IServiceProvider services) File "Task.cs", line 1914, in void Task.ThrowAsync(Exception exception, SynchronizationContext targetContext)+(object state) => { } targetContext.Post(static state => ((ExceptionDispatchInfo)state!).Throw(), edi); File "/Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs", line 36, col 19, in void SyncContext.Post(SendOrPostCallback d, object state)+() => { } File "/Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs", line 37, col 6, in void RunnableImplementor.Run() File "/Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.Lang.IRunnable.cs", line 84, col 4, in void IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) File "/Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs", line 22, col 5, in void JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)

Thanks

JaneySprings commented 2 months ago

Hi @abelgarciasaiz ! I can't reproduce it on my tablet devices. Can you, please, do the following:

  1. Create the .cs file in your project with the following content:
    
    using System.Diagnostics;
    using System.Net;
    using System.Net.Sockets;
    using Microsoft.Extensions.DependencyInjection.Extensions;

namespace HotReloadBug;

public static class BuilderExtensions { public static MauiAppBuilder TestHotReload(this MauiAppBuilder builder) { builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IMauiInitializeService, Server>(_ => new Server())); return builder; } }

internal class Server : IMauiInitializeService { private int idePort = 9988;

public async void Initialize(IServiceProvider services) {
    var tcpListener = new TcpListener(IPAddress.Loopback, idePort);
    try {
        tcpListener.Start();
    } catch (Exception e) {
        Debug.WriteLine($"[TEST]: {e.Message}");
        return;
    }

    using var client = await tcpListener.AcceptTcpClientAsync();
    using var stream = client.GetStream();
    using var reader = new StreamReader(stream);
    using var writer = new StreamWriter(stream) { AutoFlush = true };

    while (true) {
        var handshake = await reader.ReadLineAsync();
        Debug.WriteLine($"[TEST]: {handshake}");
        await writer.WriteLineAsync($"handshake_2.0.0");

        string? response = null;
        while (response == null) {
            Debug.WriteLine("[TEST]: Waiting for response...");
            response = await reader.ReadLineAsync();
        }

        Debug.WriteLine($"[TEST]: {response}");
    }
}

}


2. Open your `MauiProgram.cs` and enable this class
```cs
builder.TestHotReload();
  1. Run the application in debug mode and apply any xaml change. You should see the orange messages in the debug console: image