Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant exceptions when building to WebGL on Unity. #390

Open
4 tasks done
noahsawyer921 opened this issue Jul 12, 2024 · 3 comments
Open
4 tasks done

Instant exceptions when building to WebGL on Unity. #390

noahsawyer921 opened this issue Jul 12, 2024 · 3 comments
Labels

Comments

@noahsawyer921
Copy link

noahsawyer921 commented Jul 12, 2024

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

Copy link

parse-github-assistant bot commented Jul 12, 2024

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@ajmeese7
Copy link

ajmeese7 commented Jul 15, 2024

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.

@LariozaFilament
Copy link

LariozaFilament commented Oct 31, 2024

Is Unity WebGL intended to be supported by Parse, but has this critical issue? Or is it not supported, and this is what happens when you try to use it? The docs don't explicitly say what Unity platforms are supported, and this is the only thing I could find which seems to be indicating its not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants