Bug 59986 - Xaramrin Forms 2.3.5.233-pre1 for Tizen throws Segmentation Fault when calling F# PCL
Summary: Xaramrin Forms 2.3.5.233-pre1 for Tizen throws Segmentation Fault when callin...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-05 14:52 UTC by Hermit DAVE
Modified: 2017-10-30 12:38 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro with Tizen, Xamarin Android and XamarinForms.Android (202.50 KB, application/x-zip-compressed)
2017-10-09 09:07 UTC, Hermit DAVE
Details
Corrected repro - web service call working (103.28 KB, application/x-zip-compressed)
2017-10-17 15:42 UTC, Hermit DAVE
Details

Description Hermit DAVE 2017-10-05 14:52:49 UTC
I am using Xamarin Forms as a part of Tizen.Net preview that recently released an update for .NET standard 2 and more. Wanting to use F#, I created PCL Profile 7 and add a few function using Type Providers.

While everything compiles just fine, the app throws Segmentation Fault.

Having tried local json it seems to work however when calling web api to return json data, it throws this exception.
Comment 1 Paul DiPietro [MSFT] 2017-10-05 14:59:40 UTC
Does your issue only occur when using the project on Tizen, or can you reproduce it on other platforms? This would probably determine if we need to redirect this.
Comment 2 Hermit DAVE 2017-10-06 11:04:45 UTC
F# lib works fine with simple usage. The moment I plugin JsonProvider, the thing goes nuts.

It fails for both Tizen and Android Xamarin forms app.

I have tried with an without async and it isn't any better

```
namespace PortableLibrary1

type MOLRegionCodes = GB | US | AU | ROW
type ConfigProvider = FSharp.Data.JsonProvider<"""{ "advert": { "banners": true, "puffMpu": true, "articleMpu": true, "sticky": true, "galleryInterstitials": true, "videoAds": true, "adsVisible": false }, "tracking": { "omniture": true }, "app": { "dev": "2017.131.1400.0", "prod": "2.1.0.0" }, "channels": [ { "sn": "home", "title": "Home", "homeChannel": true, "autoSync": true, "channelColour": "#FF004DB3", "channelInsetColour": "#FFE6EEF8", "calloutBackgroundColour": "#FFF3FFF3", "calloutForegroundColour": "#FF0A50B0" }, { "hidden": true, "sn": "video", "title": "Video", "channelColour": "#FF004DB3", "channelInsetColour": "#FFE6EEF8", "calloutBackgroundColour": "#FFF3FFF3", "calloutForegroundColour": "#FF0A50B0" } ] }""">
type Channel = { Type : string; Title : string; MainColor : string; InsetColor : string }


type Class1() = 
    let bar =
        async {
             do! Async.Sleep(100)
             return 42
        }

    let getRegionCode country =
        match country with
        | "gb" -> MOLRegionCodes.GB
        | "us" -> MOLRegionCodes.US
        | "au" -> MOLRegionCodes.AU
        | _ -> MOLRegionCodes.ROW
            

    let internalGetConfiguration =
        async {
            let countryCode = System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName.ToLowerInvariant() 
            let regionCode = getRegionCode countryCode
            let configurationUrl = "http://api.dailymail.co.uk/native/4.0/settings/windows/2300/" + regionCode.ToString()
        
            let! config = ConfigProvider.AsyncLoad(configurationUrl)
            return config
        }

    let internalGetChannels =
        async {
            let! config = internalGetConfiguration
            return config.Channels |> Array.filter (fun x -> x.Hidden.IsSome && x.Hidden.Value) |> Array.map (fun c -> { Type = c.Sn; Title = c.Title; MainColor = c.ChannelColour; InsetColor = c.ChannelInsetColour })
        }

    member public this.getChannels() = Async.StartAsTask(internalGetChannels)

    member public this.asyncBar() = Async.StartAsTask(bar)

    member this.X = "F#"
```
Comment 3 Paul DiPietro [MSFT] 2017-10-06 17:46:38 UTC
Could you please test against 2.4.0 stable (there are many more fixes in the release) and possibly upload a minimized reproduction to run? Does the crash only occur with F#?
Comment 4 Hermit DAVE 2017-10-09 09:07:30 UTC
Created attachment 25214 [details]
Repro with Tizen, Xamarin Android and XamarinForms.Android
Comment 5 Hermit DAVE 2017-10-09 09:21:51 UTC
I have tried Xamarin.Android and Xamarin Forms with 2.4 nuget, both fail with unhandled exception when calling the f# lib
Comment 6 Hermit DAVE 2017-10-17 09:23:34 UTC
Do you need anything else from me ? I have uploaded a repro on the 9th October
Comment 7 Paul DiPietro [MSFT] 2017-10-17 14:32:13 UTC
If you do a try/catch around await MolTvCommon.MolApi.getChannels, it returns the following:

{System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
Response from http://api.dailymail.co.uk/native/4.0/settings/windows/2300/US:
Internal Server Error ---> System.Net.WebException: The remote server returned an error...

Catching the exception allows the application to continue as expected, so I believe there isn't explicitly a Forms issue here and that something is wrong with the request being made. I unfortunately don't know enough about this to be of immediate help, but it's a starting point for investigating why the error is thrown.
Comment 8 Hermit DAVE 2017-10-17 15:06:32 UTC
@Paul apologies... looks like its my fault.. the API is case sensitive and ensuring us in lower case works at least on android. I am trying to get it to work on Tizen (though it is having debugger issues now).
Comment 9 Hermit DAVE 2017-10-17 15:42:11 UTC
Created attachment 25335 [details]
Corrected repro - web service call working

Android Forms project with v2.4.0 works correctly.
Tizen Forms project with pre-release references fails.

I have tried upgrading references but they also fail with 
* The XamlCTask could not be initialized with its input parameters
* The DebugType parameter is not supported by XamlCTask task.
Comment 10 Hermit DAVE 2017-10-17 15:43:27 UTC
@Paul I still have issue on Tizen after fixing the webservice call. It works with Android Forms project
Comment 11 Kangho Hur 2017-10-19 07:55:16 UTC
Could you please share log message? 

#sdb root on 
#sdb shell
#journalctl -f
Comment 12 Kangho Hur 2017-10-19 08:07:08 UTC
One more thing, in order to connect internet, you should add internet privilidge to tizen-mainfest.xml as below.

<privileges>
    <privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
Comment 13 Hermit DAVE 2017-10-30 12:38:11 UTC
@Kangho thanks. I was on holiday and didn't have access to my device but adding the privilege fixes the error.

Thank you.

Note You need to log in before you can comment on or make changes to this bug.