xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

MissingMethodException for Entry control in Xamarin.Forms.Platform.WPF #2033

Closed JessieArr closed 6 years ago

JessieArr commented 6 years ago

Description

Xamarin.Forms.Platform.WPF app crashes when created with the MasterDetail template (although it seems to be related to the Entry and Editor controls specifically.)

Steps to Reproduce

  1. Follow this Xamarin.Forms WPF Quick-Start Guide: https://mohachouch.github.io/Xamarin-Forms-WPF-QuickStart/
  2. Instead of selecting Blank App for the Xamarin cross-platform template, select Master Detail.
  3. Build and run the WPF project.
  4. Select "Add" from the top bar.
  5. Application crashes.

Expected Behavior

NewItemPage is rendered successfully.

Actual Behavior

Application crashes with the following exception: System.MissingMethodException: 'Method not found: 'Int32 Xamarin.Forms.InputView.get_MaxLength()'.'

Stack Trace: at Xamarin.Forms.Platform.WPF.EntryRenderer.UpdateMaxLength() at Xamarin.Forms.Platform.WPF.EntryRenderer.OnElementChanged(ElementChangedEventArgs`1 e) in C:\agent_work\1\s\Xamarin.Forms.Platform.WPF\Renderers\EntryRenderer.cs:line 41

Basic Information

Additional Information

Commenting out the editable text fields (Entry, and Editor) on the ContentPage allows it to render successfully. The full XAML for the page is here:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="Systematizr.Views.NewItemPage"
             Title="New Item">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Save" Clicked="Save_Clicked" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
        <StackLayout Spacing="20" Padding="15">
            <Label Text="Text" FontSize="Medium" />
            <Entry Text="{Binding Item.Text}" FontSize="Small" />
            <Label Text="Description" FontSize="Medium" />
            <Editor Text="{Binding Item.Description}" FontSize="Small" Margin="0" />
            <!--<Editor Text="Example" FontSize="Small" />-->
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

And the Codebehind:

using System;
    using System.Collections.Generic;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    using Systematizr.Models;
    namespace Systematizr.Views
    {
        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class NewItemPage : ContentPage
        {
            public Item Item { get; set; }
            public NewItemPage()
            {
                InitializeComponent();
                Item = new Item
                {
                    Text = "Item name",
                    Description = "This is an item description."
                };
                BindingContext = this;
            }
            async void Save_Clicked(object sender, EventArgs e)
            {
                MessagingCenter.Send(this, "AddItem", Item);
                await Navigation.PopModalAsync();
            }
        }
}

============================================= Please let me know if there is any other information I can provide. Thank you for your time!

PS - I'm super excited about WPF support! Thanks to you all for your hard work on this feature! :D

mohachouch commented 6 years ago

Hello, I tried to reproduce the bug but I did not have the error you had.

Can you attached a test program.

JessieArr commented 6 years ago

I'm at work right now, but can do so once I get home this evening. What is the best way to share it? Shall I just Zip the Solution and project folders? Or would you prefer I create a public Github repo?

PS - Thanks for the quick start guide! It was very helpful. :)

mohachouch commented 6 years ago

You are welcome

Zip the solution it’s a good solution.

JessieArr commented 6 years ago

I created a new solution from scratch using the above steps and was able to reproduce the issue. You can download the Zipped solution here (22MB): https://www.dropbox.com/s/en8n5jypy9l3yys/HelloWPF.zip?dl=0

It is also publicly available on my Github if that is easier: https://github.com/JessieArr/HelloWPF

To reproduce, simply set HelloWPF.WPF as your startup project in Visual Studio and then hit "Start" in Debug mode on AnyCPU.

Note also that I am using https://www.myget.org/F/xamarinforms-ci/api/v2 as my package source for Xamarin Forms Nightly builds - it was mentioned in one of the project's blog posts, and I am assuming it is still current. If that assumption is incorrect, it could be the cause of this issue, but the version numbers look current to me so I think it's still valid.

mohachouch commented 6 years ago

You should not use the myget source package anymore. It was used before the merge with Xamarin Forms.

Regarding the error, you use two version of Xamarin Forms. Please update all packages to the latest version 2.6.0-nightly ....

JessieArr commented 6 years ago

Ah, that resolved it. My apologies, Xamarin.Forms.Platform.WPF lists the same version of Xamarin.Forms as a dependency - I had assumed it would also pull in the required version when I added it to the solution. As soon as I updated them both I actually got a compiler error about a version mismatch that required me to restart VS. I assume this was probably added in a more recent version of Xamarin Forms than I was using.

Thanks for your time, sorry the issue was something so silly.

Regarding the package source - what is the new package source for Nightly builds? The one I'm using is still listed for Nightly Builds in the project wiki: https://github.com/xamarin/Xamarin.Forms/wiki/Nightly-Builds

mohachouch commented 6 years ago

Sorry I was wrong.

Nightly build : https://www.myget.org/F/xamarinforms-ci/api/v2