heroiclabs / nakama-unity

Unity client for Nakama server.
https://heroiclabs.com/docs/unity-client-guide
Other
407 stars 75 forks source link

IEnumerable<IApiStorageObject>' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'IEnumerable<IApiStorageObject>' could be found (are you missing a using directive or an assembly reference?) #169

Closed iammuho closed 6 months ago

iammuho commented 6 months ago

Hello team,

I've copied the code in the docs directly and getting below error:

public class HatsStorageObject
{
    public string[] Hats;
}

var readObjectId = new StorageObjectId
{
    Collection = "Unlocks",
    Key = "Hats",
    UserId = session.UserId
};

var result = await client.ReadStorageObjectsAsync(session, new [] { readObjectId });

if (result.Objects.Any())
{
    var storageObject = result.Objects.First();
    var unlockedHats = JsonParser.FromJson<HatsStorageObject>(storageObject.Value);
    Debug.LogFormat("Unlocked hats: {0}", string.Join(",", unlockedHats.Hats));
}

error:

 'IEnumerable<IApiStorageObject>' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'IEnumerable<IApiStorageObject>' could be found (are you missing a using directive or an assembly reference?)

Is there an update in the codebase but not reflected to docs ?

Unity version : 2022.3.20f1 Nakama Package Version:3.10.1

novabyte commented 6 months ago

@iammuho Looks like the code example assumes that the System.Linq namespace has been imported:

https://learn.microsoft.com/en-us/dotnet/csharp/linq/

We'll update the documentation to make it clearer or remove the implicit use of System.Linq but otherwise the code example looks correct. /cc @heroiclabs/devrel

Please re-open this issue if the problem persists after you use Linq.