Mahdi Tahsildari
Mahdi Tahsildari

Reputation: 13582

Same Android app who runs on Debug mode, crashes on release mode

I've written a simple app using Xamarin for Visual Studio and C# language. The code is:

    HubConnection hubConnection;
    IHubProxy chatHubProxy;
    async void btnConnect_Click(object sender, EventArgs e)
    {
        try
        {
            TextView log = FindViewById<TextView>(Resource.Id.txtLog);
            base.OnResume();

            hubConnection = new HubConnection("http://192.168.1.3:2010/signalr");

            chatHubProxy = hubConnection.CreateHubProxy("MyHub");

            chatHubProxy.On<string>("AddMessage", (message) =>
            {
                TextView text = FindViewById<TextView>(Resource.Id.txtLog);
                text.Text = message;
            });

            var localIP = "192.168.1.104"; //the android device has this IP

            await hubConnection.Start();

            var srvrMessage = chatHubProxy.Invoke<string>("LoginFromMobile", "mahdi", "p@SsW0Rd",
                hubConnection.ConnectionId, localIP);
            if (srvrMessage != null)
            {
                log.Text = srvrMessage.Result;
            }
            else
                log.Text = "can't connect to server";
        }
        catch (Exception ex)
        {
            TextView text = FindViewById<TextView>(Resource.Id.txtLog);
            text.Text = ex.StackTrace;
        }
    }

When I click the "Connect" button, I get connected to a SignalR Hub located on my pc in the network, and everything works fine in DEBUG mode. But unfortunately, when I compile the same app in RELEASE mode, I get the following error:

enter image description here

I can't see why... Please tell me what I need to consider to make the app work right in Release mode too. Is there any permission problem? Some config or setting missing? Your guides are truly helpful and appreciated.

Upvotes: 1

Views: 4978

Answers (2)

gulawaiz
gulawaiz

Reputation: 11

Linking to "Sdk Assemblies only" fixed my problem.

Upvotes: 0

Ben Bishop
Ben Bishop

Reputation: 1414

If something works in Debug mode but does not in Release mode then most likely the issue is that the Linker is not including your dll when it generates the Release binary.

If you double click on your Android project in the Solution Explorer you can change the setting under Build -> Android Build.

You'll need to select Release for your configuration and then select the Linker tab. If you select "Don't Link" all dlls your project reference will be include in the Release binary. This will lead to a larger binary size but will help you diagnose if this it the problem.

You can read more about the Linker from the Xamarin docs: https://developer.xamarin.com/guides/ios/advanced_topics/linker/

Upvotes: 5

Related Questions