ModuleNotFoundException Issue

Hello, I'm struggling with an error that I can't figure out at all. I followed the cloud code tutorials listed below :


https://docs.unity.com/ugs/en-us/manual/cloud-code/manual/modules/how-to-guides/run-modules/unity-runtime
https://docs.unity.com/ugs/en-us/manual/cloud-code/manual/modules/how-to-guides/write-modules/unity-editor

I have all the generated required files correctly, as it zips and uploads correctly without any compile issues

Deployment window :
9852114--1418460--1.PNG

Error here :
9852114--1418463--2.PNG

Dashboard :
9852114--1418466--3.PNG

My client code :

using System;
using Unity.Services.Authentication;
using Unity.Services.CloudCode;
using Unity.Services.Core;
using UnityEngine;
using Unity.Services.CloudCode.GeneratedBindings;
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;

[Serializable]
public class UnityAuthTokens
{
    public string accessToken;
    public string sessionToken;
}

public class UnityGamingServicesManager : GenericManager<UnityGamingServicesManager>
{
    private string unityPlayerId;
    private UnityAuthTokens authTokens;
    private bool isAuthInitialized = false;

    public string UnityPlayerId { get => unityPlayerId; }

    public Action<string> onLoginSuccess;
    public Action<string> onLoginFailure;

    async void Awake()
    {
        base.Awake();

        onLoginSuccess += SayHello;

        try
        {
            await UnityServices.InitializeAsync();
            Debug.Log("Unity Services Initialized");
            isAuthInitialized = true;
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
    }

    public async void SayHello(string playerId)
    {
        try
        {
            Debug.Log("[SayHello] called");
            var module = new HelloWorldBindings(CloudCodeService.Instance);
            //var module = new SudokuCloudCodeBindings(CloudCodeService.Instance);
            var result = await module.SayHello(playerId);
        }
        catch (CloudCodeException ex)
        {
            Debug.Log(ex.Message);
        }
    }

    public void SetUnityAuthTokens(UnityAuthTokens _unityAuthTokens)
    {
        authTokens = _unityAuthTokens;
        StartCoroutine(WaitUntilAuthInitialized());
    }

    IEnumerator WaitUntilAuthInitialized()
    {
        yield return new WaitUntil(() => isAuthInitialized);
        SignUserWithCustomTokenWithAutoRefresh();
    }

    async void SignUserWithCustomTokenWithAutoRefresh()
    {
        try
        {
            // Check if a cached player already exists by checking if the session token exists
            if (AuthenticationService.Instance.SessionTokenExists)
            {
                // This call will sign in the cached player.
                await AuthenticationService.Instance.SignInAnonymouslyAsync();
                Debug.Log("Cached user sign in succeeded!");
            }
            else
            {
                AuthenticationService.Instance.ProcessAuthenticationTokens(authTokens.accessToken, authTokens.sessionToken);
            }

            unityPlayerId = AuthenticationService.Instance.PlayerInfo.Id;
            Debug.Log($"unityPlayerId: {unityPlayerId}");
            onLoginSuccess.SafeInvoke(unityPlayerId);
        }
        catch (AuthenticationException ex)
        {
            // Compare error code to AuthenticationErrorCodes
            // Notify the player with the proper error message
            Debug.LogException(ex);
            onLoginFailure.SafeInvoke(ex.Message);
        }
        catch (RequestFailedException ex)
        {
            // Compare error code to CommonErrorCodes
            // Notify the player with the proper error message
            Debug.LogException(ex);
            onLoginFailure.SafeInvoke(ex.Message);
        }
        catch (Exception ex)
        {
            // Handle exceptions from your method call
            Debug.LogException(ex);
            onLoginFailure.SafeInvoke(ex.Message);
        }
    }
}

My Example.cs from the auto generated solutions :

using Unity.Services.CloudCode.Core;

namespace HelloWorld;

public class MyModule
{
    [CloudCodeFunction("SayHello")]
    public string Hello(string name)
    {
        return $"Hello, {name}!";
    }
}

Project structure for both generated solutions :
9852114--1418469--4.PNG

9852114--1418472--5.PNG

I've tried the following :
I deleted an environment named "test", created a completely new "testing" environment.
I suspected an issue with my SudokuCloudCode bindings, so created a new HelloWorld as is in the tutorial.

What am I doing wrong here? Any help is appreciated, thank you!

Hi @ajinkyanazare ,

I believe the issue could be that your client code is not currently configured to use the testing environment on line 38 -

       var options = new InitializationOptions();

       options.SetEnvironmentName("testing");
       await UnityServices.InitializeAsync(options);

via https://docs.unity.com/ugs/manual/overview/manual/service-environments#Accessing_environments_within_Unity_projects

Doesn't seem to work. To double check, I recreated the HelloWorld module and generated the solution and bindings, re-deployed to the "testing" environment, my editor environment is set to "testing" as well. Posting the full error message below :

ScriptError
(422) HTTP/1.1 422 Unprocessable Entity
Unprocessable Entity
Invocation Error
ScriptRunner.Exceptions.ModuleNotFoundException: Module with the name HelloWorld was not found. Ensure that it is published to Cloud Code for the correct environment


UnityEngine.Debug:LogError (object)
Unity.Services.CloudCode.CloudCodeInternal:BuildException (bool,long,int,string,Unity.Services.CloudCode.Internal.Http.HttpException) (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/CloudCode.cs:181)
Unity.Services.CloudCode.CloudCodeInternal/<GetRunModuleScriptResponse>d__16:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/CloudCode.cs:149)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Response`1<Unity.Services.CloudCode.Internal.Models.RunModuleResponse>>:SetException (System.Exception)
Unity.Services.CloudCode.CloudCodeInternal/<GetModuleResponseAsync>d__21:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/CloudCode.cs:243)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Response`1<Unity.Services.CloudCode.Internal.Models.RunModuleResponse>>:SetException (System.Exception)
Unity.Services.CloudCode.Internal.Apis.CloudCode.CloudCodeApiClient/<RunModuleAsync>d__7:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Apis/CloudCodeApi.cs:138)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Http.HttpClientResponse>:SetResult (Unity.Services.CloudCode.Internal.Http.HttpClientResponse)
Unity.Services.CloudCode.Internal.Http.HttpClient/<MakeRequestAsync>d__2:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Http/HttpClient.cs:44)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Http.HttpClientResponse>:SetResult (Unity.Services.CloudCode.Internal.Http.HttpClientResponse)
Unity.Services.CloudCode.Internal.Http.HttpClient/<CreateWebRequestAsync>d__4:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Http/HttpClient.cs:69)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Http.HttpClientResponse>:SetResult (Unity.Services.CloudCode.Internal.Http.HttpClientResponse)
Unity.Services.CloudCode.Internal.Http.HttpClient/<CreateHttpClientResponse>d__6:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Http/HttpClient.cs:105)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.CloudCode.Internal.Http.HttpClientResponse>:SetResult (Unity.Services.CloudCode.Internal.Http.HttpClientResponse)
Unity.Services.CloudCode.Internal.Http.HttpClient/<>c__DisplayClass6_0/<<CreateHttpClientResponse>b__0>d:MoveNext () (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Http/HttpClient.cs:102)
System.Threading.Tasks.TaskCompletionSource`1<Unity.Services.CloudCode.Internal.Http.HttpClientResponse>:SetResult (Unity.Services.CloudCode.Internal.Http.HttpClientResponse)
Unity.Services.CloudCode.Internal.Http.UnityWebRequestHelpers/<>c__DisplayClass0_0:<GetAwaiter>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.cloudcode@2.6.2/Runtime/com.unity.services.cloudcode.internal/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

Hi!

The team is looking at it, we suspect it might have something to do with a cached authentication token.

Could you provide us the exact package versions you're using for CC?

Also, could you try this very simple snippet in both your test and production environment?

using System.Collections.Generic;
using Unity.Services.Authentication;
using Unity.Services.CloudCode;
using Unity.Services.CloudCode.GeneratedBindings;
using Unity.Services.Core;
using UnityEngine;

public class CloudCall : MonoBehaviour
{
    bool m_Running;

    async void Update()
    {
        //Initialize the Services
        if (m_Running)
            return;
        m_Running = true;

        await UnityServices.InitializeAsync();

        await AuthenticationService.Instance.SignInAnonymouslyAsync();

        var module = new myccmBindings(CloudCodeService.Instance);

        var result = await module.SayHello("Hello");

        Debug.Log(result);
    }
}

Let us know if that works.

Cheers!

Yes looks like as long as I don't sign in with Custom ID, the call to cloud code goes through. Although the cached token and/or the auth and session tokens I have comes from my own custom authentication service, which calls the Unity Game Services Token Exchange API to retrieve the same for the client auth. I followed the tutorial here :
https://docs.unity.com/ugs/en-us/manual/authentication/manual/platform-signin-custom-id

For now, I can do with the anonymous sign in, although hopefully this will be fixed in a later version.

The package versions in my editor :
Cloud Code - 2.6.2
Deployment - 1.3.0

Dependencies in the generated solution :
Com.Unity.Services.CloudCode.Apis - 0.0.9
Com.Unity.Services.CloudCode.Core - 0.0.1

Hope this helps, thanks!

We're suspecting you're using an token from a different environment sign-in.
Try clearing the cache with this:
AuthenticationService.Instance.ClearSessionToken();

This fixed it! Thank you so much!


It helped me also, Thank you.