parse-community / parse-community/Parse-SDK-dotNET

Instant exceptions when building to WebGL on Unity.

Open
#390 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
C#
Stars
335
Forks
258
PR merge metrics
No merged PRs in 30d

Description

New Issue Checklist
Issue Description

An ArgumentException and many other similar exceptions are occuring whenever building a Unity build with Parse onto a WebGL release. This exception occurs as soon as the project is run in the browser, as well as whenever I attempt to use any Parse methods, such as ParseClient.Instance.LogInAsync(string username, string password) in the browser.

Example Exception:

ArgumentException: Cannot register a type that does not implement the default constructor!
  at Parse.Platform.Objects.ParseObjectClassController.AddValid (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 

When exceptions are set to display the full exception and stack trace in the build settings, I also get this as the first exception, but in any attempts after that (for instance, in the Update loop), I instead get a NullReferenceException.

ArgumentException:

ArgumentException: Cannot register a type that does not implement the default constructor!
  at Parse.Platform.Objects.ParseObjectClassController.AddValid (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Parse.Platform.Objects.ParseObjectClassController.AddIntrinsic () [0x00000] in <00000000000000000000000000000000>:0 
  at Parse.ParseClient..ctor (Parse.Abstractions.Infrastructure.IServerConnectionData configuration, Parse.Abstractions.Infrastructure.IServiceHub serviceHub, Parse.Abstractions.Infrastructure.IServiceHubMutator[] configurators) [0x00000] in <00000000000000000000000000000000>:0 
  at ParseClientInitializer.Awake () [0x00000] in <00000000000000000000000000000000>:0 

NullReferenceException:

System.NullReferenceException: Object reference not set to an instance of an object.
  at Parse.UserServiceExtensions.LogInAsync (Parse.Abstractions.Infrastructure.IServiceHub serviceHub, System.String username, System.String password, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 
  at ParseClientInitializer.LoginParseClient (LoginCredentials loginCreds) [0x00000] in <00000000000000000000000000000000>:0 
  at JavascriptHook.ReceiveLoginCredentials (System.String loginJson) [0x00000] in <00000000000000000000000000000000>:0 
  at JavascriptHook.Start () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at JavascriptHook.Start () [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
JavascriptHook:ReceiveLoginCredentials(String)
<Start>d__6:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(<Start>d__6&)
JavascriptHook:Start()

Full example code:

    void Awake()
    {
        var connectionDataClient = new ParseClient(new ServerConnectionData
        {
            ApplicationID = "APP_ID",
            ServerURI = "http://127.0.0.1:1337/parse/",
            Key = "FAKE_API_KEY",
            MasterKey = "FAKE_MASTER_KEY"
        },
            new LateInitializedMutableServiceHub { },
            new MetadataMutator
            {
                EnvironmentData = new EnvironmentData { OSVersion = SystemInfo.operatingSystem, Platform = $"Unity {Application.unityVersion} on {SystemInfo.operatingSystemFamily}", TimeZone = TimeZoneInfo.Local.StandardName },
                HostManifestData = new HostManifestData { Name = Application.productName, Identifier = Application.productName, ShortVersion = Application.version, Version = Application.version }
            },
            new AbsoluteCacheLocationMutator
            {
                CustomAbsoluteCacheFilePath = $"{Application.persistentDataPath.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}Parse.cache"
            }
        );
        connectionDataClient.Publicize();
    }
    public void LoginParseClient(string username, string password)
    {
        ParseClient.Instance.LogInAsync(username, password);
    }
    public void Start() {
       LoginParseClient("myUsername", "myPassword");
    }

Has anyone else encountered this issue before? Is there any workarounds, or is Unity web deployment not supported?

Steps to reproduce
  1. Create a unity project. Add Parse.dll to Assets/Plugins.
  2. Create a code file with a ParseClient initialization connecting to an existing parse server with code for logging in a user with LogInAsync.
  3. Observe that the code runs correctly when running on a local test.
  4. Set target build platform to WebGL
  5. Set webGL settings for maximum web compatability. Build settings --> Publishing settings --> Turn on stack traces, set compression to Gzip, turn on compression fallback
  6. Build and run
Actual Outcome

When loading in files that use code from ParseInfrastructure, it causes an ArgumentException on startup. From then on, any uses of the code cause a NullReferenceException. The errors and stack traces are seen above.

Expected Outcome

The code should simply log in the user.

Environment

Unity 2022.3.31f1

Server

  • Parse Server version: 3.0.2
  • Operating system: MacOS Sonoma 14.4.1
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: n/a
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • Parse .NET SDK version: 3.0.2
Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure in a Unity 2022.3.31f1 WebGL build using the reported ParseClient initialization and LogInAsync flow. Start with Parse.Platform.Objects.ParseObjectClassController.AddValid/AddIntrinsic and the ParseClient constructor shown in the stack trace, then trace the subsequent NullReferenceException. Done means the WebGL build initializes Parse and logs in without either exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.