parse-community / Parse-SDK-dotNET

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

Ability to compile dotNET SDK within Unity #354

Closed keerthik closed 3 years ago

keerthik commented 3 years ago

New Issue Checklist

Issue Description

Unity support in the 2.0 development branch. Parse SDK dotNET 2.0.0 development and master branch use .NET language features available in C# 5.0 or newer. Latest Unity still supports only up to .NET 4.0. Realistically, there is no timeline for Unity to upgrade past .NET Framework 4.6.

Steps to reproduce

Actual Outcome

A massive list of compile errors in the Unity editor, first failure in most files due to type-testing pattern matching which is a C# 7.0 feature.

Expected Outcome

With minor tweaks, as suggested in the README.md file to be able to build and compile Parse from within the Unity editor along with the main Unity application.

Environment

Server

Database

Client

Logs

Over 1000 errors. Example: Infrastructure/RelativeCacheLocationMutator.cs(18,64): error CS1525: Invalid expression term '{'

TobiasPott commented 3 years ago

Hi @keerthik,

I'm unsure what your project setup exactly looks like but according to your description it looks to me like you have imported the sources into your Unity project.

I'm not sure why you would want to use the complete checked out repository into your Unity project as it also includes a Tests-project which is not event intended to be used outside the SDKs visual studio solution. The project is not intended to be build by Unity but the Parse.dll assembly built with Visual Studio or the dotnet CLI can be used within Unity.

Please build the solution instead and use the Parse.dll generated in your Unity project. https://github.com/parse-community/Parse-SDK-dotNET#net-core-cli Doing so results in no errors in my case and would allow you to further progress with the given guidance in the readme file.

For the record, this issue is not related to the supported .NET version as it compiles down to a .NET Standard 2.0 assembly which is supported to be used in Unity.

Best regards, Tobias

keerthik commented 3 years ago

Thanks for reviewing. I was a bit confused earlier, let me clarify -- Parse .NET SDK master uses C# 8.0 features, like pattern matching and null coalescing assignment. Unity C# compiler supports different C# versions depending on Unity Editor version.

A workflow with the last official Parse SDK release (v1.8.0) allowed it to be imported into almost any Unity Editor version project as C# source code. This allowed deeper debugging and modification of the Parse code in the client while being compatible with Unity C#.

While I understand this wasn't supported behaviour, it was certainly critical to keeping a working application. For example, v1.8.0 SDK did not provide a public method for clearing the cached ParseUser, and also created an error when logging a user out with an invalid session token — so if for any reason the user's sessiontoken was invalidated remotely, an app reinstall was the only resolution to being able to log in again. Since I had imported SDK source code, I was able to reproduce this error, and expose the CurrentUserController.ClearFromDisk() operation to the client application. This would be much more challenging to identify, reproduce, debug and resolve without being able to have Parse SDK code and client code accessible and debuggable in the same build environment.

I understand if this was not and is not intended support, and you can close the issue — just noting that it was a quality of life booster to Unity development that relied on the Parse .NET SDK.

Upon further exploration, I just discovered that Unity 2020.3 and newer supports C# 8.0 and the Parse source code has no compiler errors, which is great news! We cannot use this Editor version yet as it drops support for some mobile devices we still target, but in the near future we may be able to upgrade to the latest Parse SDK and Unity Editor.

TobiasPott commented 3 years ago

Hi @keerthik, I wonder where you got an 'official' version 1.8.0 of the SDK from as I can't find it neither here on github nor in nuget. Could you please point out to which version you are referring? (the current official release is still 1.7.0 and the 2.0.0 is marked as development state).

The direct support for compilation in Unity is nothing on the agenda at the moment, due to the problem that Unity controls which features are available and which are not and the compilation into a dll/assembly works around this limitation/situation with the Unity platform.

I understand the difficulty which comes with the lack of direct source access within Unity in regards of debugging and error track down. Thus said you are welcome to point out the mentioned issues with clearing cached users if they occur with the 2.0.0 develop branch and suggest changes for it. I assume this is an issue others may come across but never got mentioned here on github to be addressed (or got lost over time).

keerthik commented 3 years ago

Thanks. I will use the 2.0.0 branch with Unity 2020.3 where it can be compiled from the Editor and see if the issue exists or not, and create a new issue or PR if so (the JS and other language versions of the SDK have this API, so if this SDK is in parity then it is unlikely to be missing).

This was the branch/tag (I believe), which is labelled 1.8.0 that I was referring to. I see now that it isn't an "official release", but it does have later commits than 1.7.0.

The version we were using in our codebase looks to be a fork of this (although not forked using git), with some minor modifications for use in Unity.