0

I am building an app within Xamarin and running into Error CS0050 for the 'Database' method name. Here is my current code:

using System.IO;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Something
{
    public partial class App : Application
        {
            private static Database database;
            public static Database Database
            {
                get
                {
                    if (database == null)
                    {
                        database = new Database(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "items.db3"));
                    }
    
                    return database;
                }
            }
    
            //adding in the local database: https://www.youtube.com/watch?v=uxqQqyuZ3Qo
    
    
            public App()
            {
                InitializeComponent();
    
                MainPage = new MainPage();
            }    
        } 
...}

I have tried changing both the 'Database' method name and the variable 'database' above it into different combinations of private/public. Each time makes more problems. This method is referenced in other files so it must be public.

I used this tutorial as a reference when creating this and he never had this issue: https://www.youtube.com/watch?v=uxqQqyuZ3Qo

Thanks for the help in advance!

Complete text: error CS0053: Inconsistent accessibility: property type 'Database' is less accessible than property 'App.Database'

Pebz
  • 1
  • 1
  • 2
    I looked up `Error CS0050`. That means `Inconsistent accessibility:`. I could tell you the fix, but I'd like you to first add to question the **complete text** of the error message it gives you. That text explains exactly what the problem is. I realize you may not understand what it is telling you, but that is where you need to start. HINT: It is easier to understand, if you *change your property name so it is different than the class name*: Change declaration to `public static Database Database1`. Notice that the error message still refers to `Database`, not `Database1`. – ToolmakerSteve Jul 18 '22 at 22:17
  • 2
    ... Also add the declaration line for `class Database`. E.g. `private class Database` or whatever the `access modifier` is. – ToolmakerSteve Jul 18 '22 at 22:24
  • This is a basic c# problem, nothing to do with XF. Is your Database class public? – Jason Jul 18 '22 at 22:26
  • Thanks for adding the complete error text. Now, it's telling you that the Database type (the class definition) is less accessible than the Database property in the App class. Your property is public, therefore the Database class needs to be public as well. That's all it's saying. I'm guessing you have it set to `private`, or perhaps `internal`? – mason Jul 19 '22 at 22:00
  • What makes you think the Database class is public? We can't tell for sure what it is, as you haven't edited it into your question. Review [mcve] please. – mason Jul 19 '22 at 22:01
  • Perfect! Crazy. It looks like it's past the bug now. Thank you! – Pebz Jul 19 '22 at 22:05

0 Answers0