FS2024 Static communication error when using PCL project using TypeProvider

He tries to create TypeProvider for Xamarin.Forms, but he suffers from error FS2024.

  • Parse your own library from XAML Xamarin.Forms
  • Assign x: Name to Propertis

`F #

type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
// made btn1 and text1 propertis

type MainPageEx(target:MainPage) =
    let mutable count = 0
    do
        // When set event to btn.Clicked, happen FS2024 error.
        // If this event is comment out, it success build.
        target.btn1.Clicked.Add( fun e ->
            count <- count + 1
            target.btn1.Text <- "Clicked " + count.ToString())
    // Property is success
    member this.CurrentPage
        with get() = target.CurrentPage

When you reference a property, assembly, and operation, you can fine. But the inner class is Xamarin.Forms, for example Button.Clicked. If you are trying to access it, this is a build error.

Sample code for the error https://github.com/moonmile/SimpleEventTypeProvider

Generating Code for XamarinFormsTypeProvider github.com/moonmile/XamarinFormsTypeProvider

Perhaps I suspect inconsistencies and occur in part of the generation of Native TypeProvider and Xamrin.Forms.Core PCL.

F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License my error!!!
isMscorlib: true
name: "System.Runtime"
PrimaryAssembly.DotNetCore.Name: "System.Runtime"
PrimaryAssembly.Mscorlib.Name: "mscorlib"

parameter error FS2024: Static linking may not use assembly that targets different profile.

, , , , MVVM. Butt Button.Clicked events , , .

?

XAML WPF, . github.com/fsprojects/FsXaml

+4
2

, .

, , , Visual F # Tools Build, FSharp.Core, PCL ( : (https://visualfsharp.codeplex.com/). , , Profile78, Profile259 FSharp.Core.dll( : " C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.0" " C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.1" ).

, , : , PCL ( MSBuild/xBuild, PCL F #):

<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids>

, Profile78, Profile259 ( 78, Xamarin.Forms nuget 259).

, , .

+2

.

Meybe, TypeProvider, F # mscorlib. btn1.Clicked, F # System.Runtime. ,

, Clicked Event , Android. , shard mscorlib System.Rutime, FS2024.

type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">

type MainPageEx() as this =
    inherit BindObject<MainPage>(new MainPage())

    // Add handlder by reflection
    let AddHandler(target:obj, eventName:string, eventMethod: obj*obj -> unit ) =
        let hdr = Action<obj,obj>( fun s e  -> eventMethod(s,e))

        let ei = target.GetType().GetRuntimeEvent(eventName)
        let dt = ei.AddMethod.GetParameters().[0].ParameterType
        let handler = new Action<obj,obj>(fun s e -> hdr.Invoke( s, new EventArgs() ))
        let handlerInvoke = handler.GetType().GetRuntimeMethod("Invoke", [|typeof<obj>; typeof<Type[]>|])
        let dele = handlerInvoke.CreateDelegate( dt, handler )
        let add = new Func<Delegate, EventRegistrationToken> ( fun t -> 
            let para = ei.AddMethod.GetParameters()
            let ret  = ei.AddMethod.Invoke( target, [|t|])
            if ret <> null then
                ret :?> EventRegistrationToken
            else
                new EventRegistrationToken()
            )
        let remove = new Action<EventRegistrationToken>( fun t -> ei.RemoveMethod.Invoke(target, [|t|]) |> ignore )
        // WindowsRuntimeMarshal.AddEventHandler<Delegate>(add, remove, dele)
        add.Invoke( dele ) |> ignore
        ()

        let mutable count = 0
        do
        (*  // build error
            target.btn1.Clicked.Add( fun e ->
                count <- count + 1
                target.btn1.Text <- "Clicked " + count.ToString())
        *)
            // add handler by reflection
            AddHandler( base.Target.btn1, "Clicked", this.ButtonClick ) 
            ()

        member this.CurrentPage
            with get() = this.Target.CurrentPage

        member this.ButtonClick(s,e) =
            count <- count + 1
            base.Target.text1.Text <- "clicked " + count.ToString()
0

All Articles