Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Connectivity changed on throws an exception and sometimes crashes the app #7393

Closed
janseris opened this issue May 21, 2022 · 9 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info high It doesn't work at all, crashes or has a big impact. platform/windows 🪟 s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working

Comments

@janseris
Copy link

janseris commented May 21, 2022

Description

When I switch between airplane mode and non-airplane mode in the train (train wifi is available) first ConnectivityChanged works well.
Every subsequent change of the connectivity throws this exception:

Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
WinRT information: The application called an interface that was marshalled for a different thread.

The application called an interface that was marshalled for a different thread. (0x8001010E (RPC_E_WRONG_THREAD))

Also, when this happens, the Connectivity.ConnectivityChanged event handler is usually (not regularly) not hit again (I print current connection status in this event handler).

Sometimes, the app crashes with this exception and sometimes it does not. The application crashes when ConnectivityChanged eventhandler is executed. The application however sometimes still crashes without entering the event handler at all.

There is no issue on Android.

Steps to Reproduce

MAUI Blazor app Debug mode

  • change internet connectivity

Version with bug

Release Candidate 3 (current)

Last version that worked well

RC 2 I think

Affected platforms

Windows

Affected platform versions

Windows 10 21H1

Did you find any workaround?

no

Relevant log output

No response

@janseris janseris added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 21, 2022
@janseris janseris changed the title Connectivity changed on Windows throws exception and sometimes crashes the app [Windows] Connectivity changed on throws an exception and sometimes crashes the app May 21, 2022
@jsuarezruiz jsuarezruiz added platform/windows 🪟 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels May 23, 2022
@jfversluis jfversluis removed the s/needs-verification Indicates that this issue needs initial verification before further triage will happen label May 23, 2022
@janseris
Copy link
Author

janseris commented May 23, 2022

Basic repro on casual Wi-Fi × airplane mode switching on Windows in sample MAUI Blazor app:

@page "/"
@implements IDisposable

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

@Connection

@code{
    string Connection { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();
        Connectivity.ConnectivityChanged += ConnectivityChanged;
    }

    public void Dispose()
    {
        Connectivity.ConnectivityChanged -= ConnectivityChanged;
    }

    void ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
    {
        Connection = e.NetworkAccess.ToString();
    }
}

@janseris
Copy link
Author

janseris commented May 23, 2022

Repro no. 2.

@page "/"
@using System.Diagnostics
@implements IDisposable

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

@Connection

@code{
    string Connection { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();
        Connectivity.ConnectivityChanged += ConnectivityChanged;
        Trace.WriteLine($"rendering page with thread {Thread.CurrentThread.ManagedThreadId}");
        ConnectivityChanged(null, null);
    }

    public void Dispose()
    {
        Connectivity.ConnectivityChanged -= ConnectivityChanged;
    }

    void ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
    {
        Trace.WriteLine($"connectivity changed event handler running on thread {Thread.CurrentThread.ManagedThreadId}");
        InvokeAsync(() =>
        {
            Connection = Connectivity.NetworkAccess.ToString(); //TEST avoid issue
        });
    }
}

@janseris
Copy link
Author

janseris commented Jun 21, 2022

Hi, any changes in the status of this issue?
The problem still happens in the current version of MAUI (6.0.4) just as before.

Example: When I share network from phone to laptop and turn internet on/off on the phone, the Windows app crashes when an event handler is registered just as shown in the sample.

@VincentBu
Copy link

not repro with vs main build(32627.385). There is no wlan module on my machine, so I change internet connectivity by connecting and disconnecting VPN.

@VincentBu VincentBu added the s/triaged Issue has been reviewed label Jun 28, 2022
@janseris
Copy link
Author

not repro with vs main build(32627.385). There is no wlan module on my machine, so I change internet connectivity by connecting and disconnecting VPN.

This issue is for any Internet connection type . Not only WiFi. You can simply disable Ethernet connection in settings, that would work as well.

@rachelkang rachelkang added this to the 6.0-servicing milestone Jun 30, 2022
@mattleibow mattleibow removed their assignment Aug 3, 2022
@samhouts samhouts added the high It doesn't work at all, crashes or has a big impact. label Sep 29, 2022
@mattleibow
Copy link
Member

mattleibow commented Oct 14, 2022

Is this bug still happening? I can't reproduce nor can I repro the other issue #9972 not the winui bug microsoft/WindowsAppSDK#2965 (comment)

If this is happening still, please update this issue with a repro sample and attach the obj\project.assets.json file so I can see exactly what versions of things you are on.

Also, attach the exact windows build using winver or using the cmd and copying the version in there.

@mattleibow mattleibow added s/needs-info Issue needs more info from the author s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Oct 14, 2022
@ghost
Copy link

ghost commented Oct 14, 2022

Hi @janseris. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Oct 14, 2022

Hi @janseris. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Oct 18, 2022
@ghost
Copy link

ghost commented Oct 18, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@ghost ghost closed this as completed Oct 21, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 21, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info high It doesn't work at all, crashes or has a big impact. platform/windows 🪟 s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants