parse-community / Parse-SDK-dotNET

Parse SDK for .NET, Xamarin, Unity.
http://parseplatform.org
Apache License 2.0
322 stars 260 forks source link

Instant exceptions when building to WebGL on Unity. #390

Open noahsawyer921 opened 1 month ago

noahsawyer921 commented 1 month ago

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

Database

Client

Logs

parse-github-assistant[bot] commented 1 month ago

Thanks for opening this issue!

ajmeese7 commented 1 month ago

I replicated the issue on Unity 2022.3.37f1, exploring currently to see if I can determine the root cause.

I've tried probably a dozen different variations of similar code and I continue to reproduce the issue, I will genuinely be shocked if this is a result of user error. There may be some incompatability or something at play, but I think the code is solid.