Hello, everyone, I want to test the code on “Parse-SDK-dotNET” (GitHub - parse-community/Parse-SDK-dotNET: Parse SDK for .NET, Xamarin, Unity.):
So:
1 according to the document set the Parse Server Server, and the “Saving your first object” (Parse Server Guide | Parse) tests pass, the diagram below:
2 I used visual studio 2022 to create a.NET command line program and import Parse’s NUGET package, but the error is as follows:
The code is as follows:
using Parse;
using Parse.Abstractions.Infrastructure;
using System;
using System.Threading.Tasks;
using static System.Formats.Asn1.AsnWriter;
class Program
{
static async Task Main(string[] args)
{
// 初始化 Parse 客户端
//var client = new ParseClient("SincereTeamMate", "http://172.31.229.18:1337/parse", "SincereTeamMate");
ParseClient client = new ParseClient("SincereTeamMate", "http://172.31.229.18:1337/parse", "SincereTeamMate");
client.Publicize();
// Create a user, save it, and authenticate with it.
await client.SignUpAsync(username: "Test", password: "Test");
Console.WriteLine("SignUp a user.");
// Get the authenticated user. This is can also be done with a variable that stores the ParseUser instance before the SignUp overload that accepts a ParseUser is called.
Console.WriteLine(client.GetCurrentUser().SessionToken);
// Deauthenticate the user.
await client.LogOutAsync();
Console.WriteLine("LogOut the user.");
// Authenticate the user.
ParseUser user = await client.LogInAsync(username: "Test", password: "Test");
Console.WriteLine("LogIn a user.");
// Create a new object with permessions that allow only the user to modify it.
ParseObject testObject = new ParseObject("TestClass") { ACL = new ParseACL(user) };
Console.WriteLine("Create a new object with permessions that allow only the user to modify it.");
// Bind the ParseObject to the target ParseClient instance. This is unnecessary if Publicize is called on the client.
testObject.Bind(client);
// Set some value on the object.
testObject.Set("someValue", "This is a value.");
Console.WriteLine("Set some value on the object.");
// See that the ObjectId of an unsaved object is null;
Console.WriteLine(testObject.ObjectId);
// Save the object to the target Parse Server instance.
await testObject.SaveAsync();
Console.WriteLine("Save the object to the target Parse Server instance.");
// See that the ObjectId of a saved object is non-null;
Console.WriteLine(testObject.ObjectId);
// Query the object back down from the server to check that it was actually saved.
Console.WriteLine((await client.GetQuery("TestClass").WhereEqualTo("objectId", testObject.ObjectId).FirstAsync()).Get<string>("someValue"));
// Mutate some value on the object.
testObject.Set("someValue", "This is another value.");
// Save the object again.
await testObject.SaveAsync();
// Query the object again to see that the change was made.
Console.WriteLine((await client.GetQuery("TestClass").WhereEqualTo("objectId", testObject.ObjectId).FirstAsync()).Get<string>("someValue"));
Console.WriteLine("now you see GetQuery could run......");
// Store the object's objectId so it can be verified that it was deleted later.
var testObjectId = testObject.ObjectId;
Console.WriteLine("Store the object's objectId ");
// Delete the object.
await testObject.DeleteAsync();
Console.WriteLine("Delete the object.");
// Check that the object was deleted from the server.
Console.WriteLine(await client.GetQuery("TestClass").WhereEqualTo("objectId", testObjectId).FirstOrDefaultAsync() == null);
Console.WriteLine("now you see GetQuery(T).WhereEqualTo() could run......");
// Deauthenticate the user again.
await client.LogOutAsync();
Console.WriteLine("Deauthenticate the user again...End All");
}
}
Please help me modify the code so that the program can run! Thank you!