1

In my Xamarin forms project, It gives me this kind of obsolete warning how to fix this

here my code

         public class CustomWebView : WebView
{
    public static readonly BindableProperty UriProperty =

        BindableProperty.Create<CustomWebView, string>(p => p.Uri, default(string));

    public string Uri
    {
        get => (string) GetValue(UriProperty);
        set => SetValue(UriProperty, value);
    }
}

how to fix this

  • 1
    Could you give us the entirety of the warning – phuzi May 30 '19 at 09:19
  • 1
    And at which line the warning is? – Yury Schkatula May 30 '19 at 09:20
  • [CS0618](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0618) appears to be warning you about using an `[Obsolete]` member. The text accompanying the warning should be very specific about which property – phuzi May 30 '19 at 09:20
  • it's not a warning entirely its more ReSharper suggestion https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0618 – Ishara Lakshitha May 30 '19 at 09:21
  • 2
    To fix it: Use the newer version of the API. But since you haven't told us which API is obsolete, we cannot help. – DavidG May 30 '19 at 09:22
  • #pragma warning disables @Jon Skeet already given an answer. https://stackoverflow.com/questions/968293/c-sharp-selectively-suppress-custom-obsolete-warnings#968311 – SUNIL DHAPPADHULE May 30 '19 at 09:29
  • @SunilDhappadhule That's a bad idea in this situation, the real solution is to new the correct API. – DavidG May 30 '19 at 09:30
  • there is no API it's just simple custom rendering part – Ishara Lakshitha May 30 '19 at 09:36

1 Answers1

2

The docs for the BindableProperty.Create method show that the generic version of this method has been deprecated since version 2.1.0 meaning you shouldn't be using it. Instead you should use the non-generic overload, so your code should look like this:

BindableProperty.Create("Uri", typeof(string), typeof(CustomWebView), default(string));
DavidG
  • 113,891
  • 12
  • 217
  • 223