Database not loading

I made an editor which i am using to make a database, this database is a scriptable object. However, every time I start unity my database can not be found (even though I can see it in the folder) and when clicking on it it says “The associated script can not be loaded. Please fix and compile errors and assign a valid script”.

This is the code that runs when opening the editor:

const string dbName = "AbilityDatabase.asset";
const string dbPath = "Databases";

void OnEnable()
{
    string dbFullPath = "Assets/" + dbPath + "/" + dbName;

    AbilityEditor db = AssetDatabase.LoadAssetAtPath(dbFullPath, typeof(AbilityEditor)) as AbilityEditor;

    Debug.LogWarning("Running this function");
    Debug.Log("db: " + db);

    if (db == null)
    {
        Debug.LogWarning("DATABASE IS NULL, MAKING A NEW ONE");
        
        //Check to see if the folder exists
        if (!AssetDatabase.IsValidFolder("Assets/" + dbPath))
            AssetDatabase.CreateFolder("Assets", dbPath);

        //Create the database and refresh the AssetDatabase
        db = ScriptableObject.CreateInstance<AbilityEditor>() as AbilityEditor;
        AssetDatabase.CreateAsset(db, dbFullPath);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
}

Whenever I open the editor I get the MAKING A NEW ONE message and the existing database (that already has data in it) is replaced with a new empty one.

I’m not sure even where to look for the error as it seems that AssetDatabase.LoadAssetAtPath() just isn’t working but Unity also gives problems before I even try to use this function.

When I start the editor when I didn’t close Unity it does work and I get the database that I had before.

what about this:

//Create the database and refresh the AssetDatabase
 db = ScriptableObject.CreateInstance<AbilityEditor>() as AbilityEditor;
 AssetDatabase.CreateAsset(db, dbFullPath);

 EditorUtility.SetDirty(db);  //tell unity that this thing actually has to be saved

 AssetDatabase.SaveAssets();
 AssetDatabase.Refresh();