Xamarin Forms: Win Phone 8.1 Silverlight offline mode using Azure

168 views Asked by At

I am creating an app that must be able to load when it is offline, for this we are using Azure and Sqlite. In the project I have downloaded the Microsoft.WindowsAzure.MobileServices.SQLiteStore package from NuGet along with its dependency package SQLitePCL. These packages are added to the PCL, android, ios and win phone projects. In ios and android everything works like a charm, however, in windows phone the reference "SQLite for Windows Phone (SQLite.WP80, Version 3.8.7.2)" added by SQLitePCL comes broken and when trying to build the project it throws the error "Could not find SDK SQLite.WP80, version=3.8.7.2". I have tried downloading older versions from NuGet to see if there is working version but I have had no luck. I also attempted removing this reference and adding it to the project externally downloading it through Visual Studio extensions and then adding the downloaded extension to the project solving the issue that the reference is broken. The version added is newer than NuGets since I was unable to find the same version. The external references version is "SQLite for Windows Phone (SQLite.WP80, version=3.10.2)". It now compiles correctly but when the code reaches the point of execution that requires this reference it throws the following error "This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.". More specifically this error is thrown when the following code executes:

if (!CrossConnectivity.Current.IsConnected)

Does anyone know how I can get this reference working since it seems to be broken in NuGet and it doesnt allow me to add it externally?

UPDATE

Added some screen captures of the packages I have in NuGet and the projects they are in (All the projects except the common and api project). Also in the Screen captures I put an image of all the references in the PCL and WinPhone projects. The only reference that isnt in the PCL are the ones specifically for windows, one of these being the reference to "SQLite for Windows (SQLite.WP80, version=3.10.2)" mentioned in the link you provided.

Azure NuGet package currently added in all projects

SQLitePCL NuGet package currently added in all projects

PCL references

WinPhone references

2

There are 2 answers

0
Orlando On BEST ANSWER

I couldn't find a solution to fix the reference itself but since the code only crashed when checking the phones connectivity I decided to look up another way to check this and came up with the following:

if (!NetworkInterface.GetIsNetworkAvailable())

Hope this is helpful if someone else runs into this issue!

2
Mario Galván On

To check the network status maybe you can use this in stead of CrossConnectivity.Current.IsConnected

using Xamarin.Forms;
using System.Net;
using System.Threading.Tasks;
using Plugin.Connectivity;

namespace XXXXXX
{
    public class NetworkHelper
    {
        #region CONSTANTS
        //2.5f
        private const float NETWORK_TIMEOUT_LIMIT = 3f; // Seconds
        private const String testUrl = "https://google.com/";
        #endregion

        public NetworkHelper ()
        {
        }

        #region PUBLIC METHODS
        public static bool CheckNetworkStatus()
        {
            bool bSuccess = false;

            try
            {
                var request = HttpWebRequest.Create(testUrl);
                request.Timeout = (int)TimeSpan.FromSeconds(NETWORK_TIMEOUT_LIMIT).TotalMilliseconds;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        Console.WriteLine("Error");
                        bSuccess = false;
                    }
                    else
                    {
                        bSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                bSuccess = false;
            }

            return bSuccess;
        }

        public static async Task<bool> IsRemoteReachable()
        {
            return await CrossConnectivity.Current.IsRemoteReachable("https://ccc.seeforge.com");
        }


        #endregion
    }
}

//Example:
var isNetworkConnected = await CheckNetworkStatus();