Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple properties with name 'BadgeView.Shared.CircleView.CornerRadius' found #11

Open
ashishbpatil1 opened this issue Nov 10, 2018 · 4 comments

Comments

@ashishbpatil1
Copy link

Details about Problem
Versions:
Xamarin.Forms: 3.3.0.967583
BadgeView: 2017.10.17

Problem

Multiple properties with name 'BadgeView.Shared.CircleView.CornerRadius' found

I am getting this error after updating xamarin forms to the latest stable version with BadgeView nuget packages.

Verbose Logs

{Xamarin.Forms.Xaml.XamlParseException: Position 8:81. Multiple properties with name 'BadgeView.Shared.CircleView.CornerRadius' found. ---> 
System.Reflection.AmbiguousMatchException: Ambiguous match found.
 at System.RuntimeType.GetPropertyImpl (System.String name, System.Reflection.BindingFlags bindingAttr, 
System.Reflection.Binder binder, System.Type returnType, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00061] in <43dbbdc147f2482093d8409abb04c233>:0 
at System.Type.GetProperty (System.String name) [0x0000e] in <43dbbdc147f2482093d8409abb04c233>:0 
at System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty (System.Type type, System.String name) [0x00006] in <43dbbdc147f2482093d8409abb04c233>:0 
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor+<>c__DisplayClass36_0.<TrySetValue>b__1 () [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:488 
--- End of inner exception stack trace ---
at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x0026d] in D:\a\1\s\Xamarin.Forms.Xaml\CreateValuesVisitor.cs:94 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000ac] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:149 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 
at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:200 
at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext) [0x00054] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:140 
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml) [0x00058] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:89 
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type callingType) [0x00026] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:67 
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.Type callingType) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ViewExtensions.cs:36 
 }

XAML code

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:badge="clr-namespace:BadgeView.Shared;assembly=BadgeView.Shared"
             x:Class="Abc.IndexPage">
    <ContentPage.Content>
        <badge:BadgeView x:Name="badgeEvent" Text="0" WidthRequest="120" BadgeColor="Red" VerticalOptions="Start" HorizontalOptions="End" />
    </ContentPage.Content>
</ContentPage>

Expected behaviour

  1. No errors
  2. It should support xamarin forms latest stable.
@ashishbpatil1
Copy link
Author

ashishbpatil1 commented Nov 12, 2018

I don't know what causes the issue but after spending 8 hour I finally made it.
So, to solve the problem I wrote custom BadgeView control just like this one but some changes in it.
(Note: I actually tried exact code but it gives same error so the changes!)

CircleView.cs
Note: Comment the CornerRadius property.

    public class CircleView : BoxView
    {
        //public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(CircleView), 0.0);
        //public double CornerRadius
        //{
        //    get { return (double)GetValue(CornerRadiusProperty); }
        //    set { SetValue(CornerRadiusProperty, value); }
        //}
    }

For android:
CircleViewRenderer.cs
Note: Added hard coded value for CornerRadius (16)

public class CircleViewRenderer : BoxRenderer
    {
        private float _cornerRadius;
        private RectF _bounds;
        private Path _path;
        public CircleViewRenderer(Context context)
           : base(context)
        {
        }
        public static void Initialize() { }
        protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
        {
            base.OnElementChanged(e);

            if (Element == null)
            {
                return;
            }
            var element = (CircleView)Element;

            _cornerRadius = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float)16, Context.Resources.DisplayMetrics);

        }

        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);
            if (w != oldw && h != oldh)
            {
                _bounds = new RectF(0, 0, w, h);
            }

            _path = new Path();
            _path.Reset();
            _path.AddRoundRect(_bounds, _cornerRadius, _cornerRadius, Path.Direction.Cw);
            _path.Close();
        }

        public override void Draw(Canvas canvas)
        {
            canvas.Save();
            canvas.ClipPath(_path);
            base.Draw(canvas);
            canvas.Restore();
        }
    }

For iOS:
CircleViewRenderer.cs
Note: Added hard coded value for CornerRadius (16)
iOS code is not tested yet.

public class CircleViewRenderer : BoxRenderer
   {
       protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
       {
           base.OnElementChanged(e);

           if (Element == null)
               return;

           Layer.MasksToBounds = true;
           //Layer.CornerRadius = (float)((CircleView)Element).CornerRadius / 2.0f;
           Layer.CornerRadius = (float)(16) / 2.0f;
       }
   }

That's it!

@pskyv
Copy link

pskyv commented Feb 28, 2019

I get the same exception after updating from xamarin forms 3.1 to 3.5 for the following code

<Grid VerticalOptions="Center"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center"> <badge:CircleView CornerRadius="40" BackgroundColor="{StaticResource primary}" HeightRequest="80" WidthRequest="80" /> </StackLayout> <StackLayout Spacing="0" Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center"> <Label Text="{Binding BindingContext.TotalOpen, Source={x:Reference Dashboard}}" TextColor="White" FontAttributes="Bold" FontSize="18" /> </StackLayout> </Grid>

@sairamb87
Copy link

I am getting the same exception, with this plugin

Xamarin.Forms.Xaml.XamlParseException: Position 8:81. Multiple properties with name 'BadgeView.Shared.CircleView.CornerRadius' found. ---> System.Reflection.AmbiguousMatchException: Ambiguous match found.

Could you please fix this issue, it will be really helpful,

Thanks

@zsigix
Copy link

zsigix commented Apr 25, 2019

The issue lies in the names of the CircleView properties CornerRadius and CornerRadiusProperty. They're declared alongside the inherited BoxView properties of the same name, which confuses reflection in later versions of Xamarin for some reason. If you put the CircleView.cs file from the repository's source into a new project with the latest Xamarin libraries installed, these properties are said to be hiding the derived members and that, if this is what you're intending (which it is), you need to use the new keyword with the property.

These issues have already been fixed with the October 2018 commit (renaming CornerRadius to BadgeCornerRadius). The NuGet repository only has the October 2017 version, however, so pushing these latest changes to it should solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants