Localization Exception: Attempting to use an invalid operation handle

I’m trying to use the Unity Localization package together with a “database” (list of things).
This database is basically a list of a class that contains an ID that the localization system can look up.
However, when trying to get a localized string via scripts, I’m getting the following exception:

Exception: Attempting to use an invalid operation handle
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.get_InternalOp () (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:454)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.get_Status () (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:542)
UnityEngine.ResourceManagement.AsyncOperations.GroupOperation.CompleteIfDependenciesComplete () (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/GroupOperation.cs:172)
UnityEngine.ResourceManagement.AsyncOperations.GroupOperation.OnOperationCompleted (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle op) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/GroupOperation.cs:225)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase1+<>c__DisplayClass57_0[TObject].<add_CompletedTypeless>b__0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle1[TObject] s) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:286)
DelegateList1[T].Invoke (T res) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:69) UnityEngine.Debug:LogException(Exception) DelegateList1:Invoke(AsyncOperationHandle1) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:73) UnityEngine.Localization.Settings.LocalizedDatabase2:GetTable(TableReference, Locale)
LocalizationUtilities:GetLocalizedString(String, String) (at Assets/Scripts/Utilities/LocalizationUtilities.cs:16)
CourseItem:GetLocalizedCoursePrefix() (at Assets/Scripts/Databases/Courses/CourseItem.cs:53)
CourseItem:GetFullCourseName(Boolean) (at Assets/Scripts/Databases/Courses/CourseItem.cs:29)
CourseSelectManager:Start() (at Assets/Scripts/Course Select/CourseSelectManager.cs:19)

The code I’m using looks like this:

    public static string GetLocalizedString(string table, string key)
    {
        if (LocalizationSettings.SelectedLocale == null)
        {
            Debug.LogWarning("No locale selected.");
            return "";
        }

        Debug.Log($"{table}    {key}");

        var localeTable = LocalizationSettings.StringDatabase.GetTable(table);
        var operation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(table, key);
        if (operation.IsDone)
            return operation.Result;

        string result = "";
        operation.Completed += op => result = op.Result;
        return result;
    }

I also tried the GetLocalizedString() method instead of the Async one, but no luck.

What am I doing wrong here?

Hi. What version of the package are you using? 1.4.3 is the latest. If it’s not visible in the package manager try changing the manifest.json file manually. It’s in the packages folder

The version I’m using is 1.3.2, and Unity doesn’t show an Update button. Just to confirm, it’s com.unity.localization I’m looking for, right?

Yes. 1.4.3 may not show but it is supported. Edit the manifest.json file in your project Packages folder to upgrade. There are a lot of fixes that may help.

Alright. That seems to have worked. Thanks!
Just a suggestion, but maybe an idea to show it in the Package Manager, since I think more people could run into this issue?

I’m on Unity 2021.3.36. This still hasn’t been solved; package manager still shows 1.3.2 as the latest. How is this possible?

The package manager requires updating for every version which is time consuming and we have not done yet. you can still use the package by changing the manif yet. est.json file in the packages folder, it just won’t be visible in the package manager.
1.5.2 is the latest

Yes, I am aware of the workaround by hardcoding the package version in the package manifest file.

All I’m saying is, if Unity is not prepared to offer long-term support for a specific Unity version, that version should not be marked as a “LTS” version, as it is highly misleading. It might even pose a violation of consumer rights and/or classify as false advertising in some jurisdistions.