parse-community / Parse-SDK-dotNET

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

Parse .NET SDK doesn't work as expected for heroku server #348

Closed ValerCheck closed 3 years ago

ValerCheck commented 3 years ago

New Issue Checklist

Issue Description

I have set up my own parse server and dashboard with free dynos on heroku. I was able to run some queries with PostMan and create users, operate with data. However when I use the most fresh Parse SDK version via nuget package v.2.0.0-develop-1 I have no possibility to access any data from my server.

Steps to reproduce

  1. Setup parse server on heroku
  2. Create console application on for example .NET core.
  3. Install the prerelease parse package v.2.0.0-develop-1
  4. Create parse client in main and try to login/signup a user
    
    var client = new ParseClient(new ServerConnectionData
    {
    ServerURI = "https://<parse-server-name>.herokuapp.com/parse",
    ApplicationID = "<parse-server-id>",
    Key = "<MasterKey>"
    });

var user = client.LogInAsync("username", "password").GetAwaiter().GetResult(); var token = client.GetCurrentUser().SessionToken; Console.WriteLine(token);


### Actual Outcome
**ParseCommandRunner.RunCommandAsync** is failing on parsing response, which looks like following for login
```lang-html
<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error</title>
    </head>
    <body>
        <pre>Cannot GET /login</pre>
    </body>
</html>

And next exception is obtained in the result: Parse.Infrastructure.ParseFailureException: 'Invalid or alternatively-formatted response recieved from server.'

Expected Outcome

Successfully signed up/logged in user

Environment

Server

Database

Client

ValerCheck commented 3 years ago

I have found, that my issue in the trailing slash in ServerURI /. In order to make it working, my custom ServerURI has to contain / in the end so it would end with parse/. Otherwise a lot of similar exceptions like I have described are appearing.

Moreover, I have a Xamarin project which also was giving me not descriptive exception, like Mono_UnhandledException in GetCustomAttribute. I have figured out this issue also. I had to setup ParseClient properly with MetadataMutator and custom EnvironmentData/HostManifestData for Xamaring project. Code above won't work for Xamarin, because default HostManifestData.Inferred calls Assembly.GetEntryAssembly() which returns null. In turn there is a code which calls GetCustomAttribute on the returned null and obviously because of that I was getting described unhandled exception. So, the section Use In Unity Client was quite helpful.