Works when compiled with VS2013 but NOT WITH VS2015

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
rkmore
Posts: 55
Joined: Mon Dec 07, 2015 1:53 pm

Works when compiled with VS2013 but NOT WITH VS2015

Postby rkmore » Tue Mar 22, 2016 11:18 am

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();
        }

    }
}

JS-Support @Userware
Site Admin
Posts: 1083
Joined: Tue Apr 08, 2014 3:42 pm

Re: Works when compiled with VS2013 but NOT WITH VS2015

Postby JS-Support @Userware » Wed Mar 23, 2016 9:47 am

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


Return to “Bug Reports”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests