Page 1 of 1

Works when compiled with VS2013 but NOT WITH VS2015

Posted: Tue Mar 22, 2016 11:18 am
by rkmore
It took me forever to find out why my code worked when I wrote my test app (at home under VS2013) but did not work when compiled at the office (under VS2015).

The code below works fine when compiled with VS2013 but when compiled with VS2015 gives the following error...

Uncaught Error: Type 'System.Runtime.CompilerServices.CallSite`1' has not been defined.

Code: Select all

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Media;

namespace HTML5_Test
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void gpsButton_Click(object sender, RoutedEventArgs e)
        {
            GetLocation();
        }

        void GetLocation()
        {
            gMainPage = this;
            CSHTML5.Interop.ExecuteJavaScript( @"navigator.geolocation.getCurrentPosition($0);", (Action<dynamic>)GpsReceived);
        }

        static MainPage gMainPage = null;
        static void GpsReceived(dynamic position)
        {
            double glat = 0;
            double glon = 0;
            glat = (double)position.coords.latitude;
            glon = (double)position.coords.longitude;
            gMainPage.ShowLatLon(glat, glon);
        }

        public void ShowLatLon(double glat, double glon)
        {
            cLatitude.Text = "Lat: " + glat.ToString();
            cLongitude.Text = "Lon: " + glon.ToString();
        }

    }
}

Re: Works when compiled with VS2013 but NOT WITH VS2015

Posted: Wed Mar 23, 2016 9:47 am
by JS-Support @Userware
Hi,

Thanks for your message.

This is due to the fact that the "dynamic" keyword is unfortunately not supported under VS 2015 with CSHTML5 due to an issue related to JSIL and the Roslyn compiler (we are going to add a more informative compilation error).

However, you can achieve the same result with the following code:

Code: Select all

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Media;

namespace HTML5_Test
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void gpsButton_Click(object sender, RoutedEventArgs e)
        {
            GetLocation();
        }

        void GetLocation()
        {
            gMainPage = this;
            CSHTML5.Interop.ExecuteJavaScript( @"navigator.geolocation.getCurrentPosition($0);", (Action<object>)GpsReceived);
        }

        static MainPage gMainPage = null;
        static void GpsReceived(object position)
        {
            double glat = 0;
            double glon = 0;
            glat = Convert.ToDouble(CSHTML5.Interop.ExecuteJavaScript("$0.coords.latitude", position);
            glon = Convert.ToDouble(CSHTML5.Interop.ExecuteJavaScript("$0.longitude", position);
            gMainPage.ShowLatLon(glat, glon);
        }

        public void ShowLatLon(double glat, double glon)
        {
            cLatitude.Text = "Lat: " + glat.ToString();
            cLongitude.Text = "Lon: " + glon.ToString();
        }

    }
}


Regards,
JS-Support