Unity showing errors when they are none in vs

So theres a problem where unity is showing errors when they are none in visual studio
Assets\Resources\PlayFabSDK\Shared\Internal\PlayFabHttp\PlayFabUnityHttp.cs(122,14): error CS1026: ) expected

I’ve checked the lines but it’s perfectly fine, I’ve restarted unity but nothing happened. Why could this be happening.
And I believe that this is more of a unity problem then a PlayFab error.

Are you able to show the problem code? Most likely it’s using a C# syntax too new for what your Unity version supports.

Errors are here:

using var www = new UnityWebRequest(reqContainer.FullUrl)
            {
                uploadHandler = new UploadHandlerRaw(reqContainer.Payload),
                downloadHandler = new DownloadHandlerBuffer(),
                method = "POST"
            };

First one is on the first line, after using, second one is between } and ; on the last line
If you want the whole method, let me know

What Unity version are you on then? I’m gonna guess it doesn’t support this ‘simple using statement’ syntax.

Normally they’re formatted:

using (UnityWebRequest www = new UnityWebRequest(reqContainer.FullUrl))
{
}

So this is kinda on playfab using syntax that’s not supported on older Unity versions.

2 Likes

Oh okay, I don’t even know why I haven’t downloaded the newer version yet lol :smile:

EDIT: Also I won’t be able to use

using (UnityWebRequest www = new UnityWebRequest(reqContainer.FullUrl))
{
}

because the script required to use www out of that function and I won’t be able to, is there any other way I can syntax this, I also don’t wanna mess with the scripting so I’d appreciate some help.
PS- I can’t update also right now, so for the time being i’ll need to rearrange it

I tried this

var www = new UnityWebRequest(reqContainer.FullUrl) { uploadHandler = new UploadHandlerRaw(reqContainer.Payload), downloadHandler = new DownloadHandlerBuffer(), method = "POST" };

it works, but just wanna make sure it’s doing the same thing as it should, it looks like it does :eyes:

No you don’t want do do that. The point of a using statement is to dispose of managed resources automatically. Not doing so will result in memory leaks.

I literally showed you the solution.

I’ve already tried that, I can’t do that before www is being defined only in that function, the script is accessing it outside of the function, so I will be getting a heap of errors, like so
8423907--1114863--upload_2022-9-8_14-45-58.png

If you looked at the documentation I linked, you would see how you would have to move logic inside the curly braces.

1 Like

Just like to confirm this is correct

            var www = new UnityWebRequest(reqContainer.FullUrl);
            using (www)
            {
                www.uploadHandler = new UploadHandlerRaw(reqContainer.Payload);
                www.downloadHandler = new DownloadHandlerBuffer();
                www.method = "POST";
            }

Again not quite.

using (var www = new UnityWebRequest(reqContainer.FullUrl))
{
    www.uploadHandler = new UploadHandlerRaw(reqContainer.Payload);
    www.downloadHandler = new DownloadHandlerBuffer();
    www.method = "POST";
   
    //rest of logic here
}

Again I can’t do that as www is being defined within the brackets, so I can’t access it outside the braces then.

Sodding hell. You put the rest of your logic that requires ‘www’ inside the curly braces. I can’t make it any more clear.

If you don’t or can’t use using, just be sure to call Dispose() when you’re done with the object.

2 Likes