I am attempting to develop a class library with Parse.com in it.
I have created an empty, clean class library, then using Nuget, added Newtonsoft.Json, Parse and Parse.NetFx45
I have then added a simple "Hello World" function taken from the Parse.com website and created a function in the class library.
Here is my function:
public async static void testParse()
{
ParseClient.Initialize("MyApplicatonID", "My.NetKey");
var testObject = new ParseObject("TestObject");
testObject["foo"] = "bar";
await testObject.SaveAsync();
}
I have then added a Unit Test project, referenced my class library and written a test as follows:
[TestMethod]
public void TestParse()
{
Experior.ParseFunctions.testParse();
}
When I run the test it throws the following error at the ParseClient.Initialize
line of:
System.TypeInitializationException was unhandled Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll Additional information: The type initializer for 'Parse.ParseClient' threw an exception.
I did some searching around one of the threads I read suggested that Parse doesn't like being wrapped in a class library...
So, I thought, I will test the same code in a Windows Forms project and call the code from a simple button.
And it works perfectly!
Can anyone see anything I am doing wrong or suggest what the problem could be please?
Any hints/tips would be greatly appreciated!
Thanks to @Samuel I have amended my code as follows:
using Parse;
using System.Threading.Tasks;
namespace ExperiorWrapper
{
public class ParseFunctions
{
public static async Task testParse()
{
ParseClient.Initialize("xxxx", "xxxx");
var testObject = new ParseObject("TestObject");
testObject["foo"] = "bar";
await testObject.SaveAsync();
}
}
}
and the test now looks like this:
[TestMethod]
public async Task TestParse()
{
await ParseFunctions.testParse();
}
The other important thing I tripped up on is that the Newtonsoft.Json, Parse and Parse.NetFx45 HAD to be added as references to the Test project to make it work...
HTH