Search Unity

Bug Localization Exception: Attempting to use an invalid operation handle

Discussion in 'Localization Tools' started by BjornGmr, Feb 12, 2023.

  1. BjornGmr

    BjornGmr

    Joined:
    Oct 18, 2021
    Posts:
    11
    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.AsyncOperationBase`1+<>c__DisplayClass57_0[TObject].<add_CompletedTypeless>b__0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] s) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:286)
    DelegateList`1[T].Invoke (T res) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.Debug:LogException(Exception)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.19.19/Runtime/ResourceManager/Util/DelegateList.cs:73)
    UnityEngine.Localization.Settings.LocalizedDatabase`2: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:
    Code (CSharp):
    1.     public static string GetLocalizedString(string table, string key)
    2.     {
    3.         if (LocalizationSettings.SelectedLocale == null)
    4.         {
    5.             Debug.LogWarning("No locale selected.");
    6.             return "";
    7.         }
    8.  
    9.         Debug.Log($"{table}    {key}");
    10.  
    11.         var localeTable = LocalizationSettings.StringDatabase.GetTable(table);
    12.         var operation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(table, key);
    13.         if (operation.IsDone)
    14.             return operation.Result;
    15.  
    16.         string result = "";
    17.         operation.Completed += op => result = op.Result;
    18.         return result;
    19.     }
    I also tried the GetLocalizedString() method instead of the Async one, but no luck.

    What am I doing wrong here?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    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
     
  3. BjornGmr

    BjornGmr

    Joined:
    Oct 18, 2021
    Posts:
    11
    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?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    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.
     
    dtaddis likes this.
  5. BjornGmr

    BjornGmr

    Joined:
    Oct 18, 2021
    Posts:
    11
    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?
     
    mhctseu, dtaddis and karl_jones like this.