MoralisWeb3 / unity-web3-game-kit

Unity Web3 Game Kit is the fastest way to connect and build games for Web3. It provides a single workflow for building high performance dapps. Fully compatible with your favourite platform.
MIT License
537 stars 219 forks source link

HttpUtility does not exist in current context #10

Closed xx014939 closed 2 years ago

xx014939 commented 2 years ago

Hi

The demo scene seems to run perfectly in it's own project. I have imported the Oculus plugin asset along with BNG framework for some VR stuff, and I am constantly getting the error "Assets\MoralisWeb3ApiSdk\Moralis\Moralis.Web3Api\Client\ApiClient.cs(120,20): error CS0103: The name 'HttpUtility' does not exist in the current context".

The specific line Unity seems to be taking issue with, is the return statement in this method

    public string EscapeString(string str)
    {
        return HttpUtility.UrlEncode(str); 
        //return RestSharp.Contrib.HttpUtility.UrlEncode(str);
    }

I'm not entirely sure how fragile this method is, so I replaced the return statement with return System.Uri.EscapeDataString(str)

This removed the error, but seems to break the code, as after going through authentication now my wallet address does no show up in the game scene.

What can I do to get this working? Thanks

xx014939 commented 2 years ago

Quick update, setting my API compatibility level (Edit > Project Settings > Player > Configuration) from .NET framework to .NET standard 2.1 seems to have removed this error.

Unfortunately I now get a runtime error

NullReferenceException: Object reference not set to an instance of an object
MoralisInterface.LogInAsync (System.Collections.Generic.IDictionary`2[TKey,TValue] authData) (at Assets/MoralisWeb3ApiSdk/Moralis/MoralisInterface.cs:177)
MainMenuScript.WalletConnectHandler (WalletConnectSharp.Core.Models.WCSessionData data) (at Assets/MoralisWeb3ApiSdk/Example/Scripts/MainMenuScript.cs:167)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <00c558282d074245ab3496e2d108079b>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <e7c72e4b0bcb4085b636d7e8921f7453>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <e7c72e4b0bcb4085b636d7e8921f7453>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <e7c72e4b0bcb4085b636d7e8921f7453>:0)

After signing the authentication request in Metamask, the wallet is not added to the game. I will update if I find a solution for this.

xactant commented 2 years ago

A couple of others have run into this as well (missing HttpUtility). Quick fix is documented here by danda_dandic: [quote] I found the problem, unity doesn’t automatically include System.Web assembly. So I’ve added csc.rps file to assets with -r:System.Web.dll. And it fixed my problem. [/quote]

Another thing to try is to delete the project files so that they are re-generated by Unity.

I will have access to an Oculus Quest in a week and will try it out and see what happens.

As to version everything should be working with .Net Standard 2.0.

I would love to hear more about your project.

Regards,

David

xactant commented 2 years ago

Though this is not an issue with the demo, leaving this open as a reminder to replace this single instance of this library due to it tripping up multiple users.

Vivraan commented 2 years ago

A couple of others have run into this as well (missing HttpUtility). Quick fix is documented here by danda_dandic: [quote] I found the problem, unity doesn’t automatically include System.Web assembly. So I’ve added csc.rps file to assets with -r:System.Web.dll. And it fixed my problem. [/quote]

Another thing to try is to delete the project files so that they are re-generated by Unity.

I will have access to an Oculus Quest in a week and will try it out and see what happens.

As to version everything should be working with .Net Standard 2.0.

I would love to hear more about your project.

Regards,

David

What is the exact procedure to add csc.rps? I can't seem to get it to work.

xactant commented 2 years ago

fix checked into features/walletconnect_integration

xx014939 commented 2 years ago

@xactant

Apologies for the late response, and thank you for continuing to work on this issue.

I’m building a 3D NFT marketplace in VR. My project is entered into the moralis hackathon, and I’m excited to show everyone what I’ve built at the end of the month.

Thanks!