Hi I am trying to query my Mongo Database by using a list of Facebook ID's as the parameter in order to return the list of users with corresponding accounts. The method works fine in the Unity Editor however when I run it on iOS I get a constructor error (I have set a blank default constructor in order to solve the issue however it still doesn't work)
Error
MissingMethodException: Method not found: 'Default constructor not found...ctor() of MongoDB.Driver.CommandResultSerializer'.
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0
at MongoDB.Bson.Serialization.Attributes.BsonSerializerAttribute.CreateSerializer (System.Type type) [0x00000] in <filename unknown>:0
at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer (System.Type type) [0x00000] in <filename unknown>:0
at MongoDB.Driver.MongoServerInstance.RunCommandAs[TCommandResult] (MongoDB.Driver.Internal.MongoConnection connection, System.String databaseName, IMongoCommand command) [0x00000] in <filename unknown>:0
at MongoDB.Driver.MongoServerInstance.Ping (MongoDB.Driver.Internal.MongoConnection connection) [0x00000] in <filename unknown>:0
at MongoDB.Driver.MongoServerInstance.Connect () [0x00000] in <filename unknown>:0
at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect (TimeSpan timeout, MongoDB.Driver.ReadPreference readPreference) [0x00000] in <filename unknown>:0
at Tacticsoft.Examples.SimpleTableViewController.FriendsHighscoreHndlr (IGraphResult FBresult) [0x00000] in <filename unknown>:0
at Facebook.Unity.AsyncRequestString+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0
Rethrow as MongoConnectionException: Unable to connect to server XXX.XXX.XX.XX:XXXX: Method not found: 'Default constructor not found...ctor() of MongoDB.Driver.CommandResultSerializer'..
at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect (TimeSpan timeout, MongoDB.Driver.ReadPreference readPreference) [0x00000] in <filename unknown>:0
at Tacticsoft.Examples.SimpleTableViewController.FriendsHighscoreHndlr (IGraphResult FBresult) [0x00000] in <filename unknown>:0
at Facebook.Unity.AsyncRequestString+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0
Initial Method
public void FetchData()
{
//data = Mongo.Instance.players.FindAll().ToList();
if (FB.IsLoggedIn)
{
FB.API("me/friends", HttpMethod.GET, FriendsHighscoreHndlr);
}
}
Callback Method
public void FriendsHighscoreHndlr (IGraphResult FBresult)
{
var dict = Json.Deserialize(FBresult.ToString()) as Dictionary<string,object>;
var friendList = new List<object>();
friendList = (List<object>)(dict["data"]);
int _friendCount = friendList.Count;
Debug.Log("Found friends on FB, _friendCount ... " +_friendCount);
List<string> friendIDsFromFB = new List<string>();
for (int i=0; i<_friendCount; i++) {
string friendFBID = getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "id");
string friendName = getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "name");
Debug.Log( i +"/" +_friendCount +" " +friendFBID +" " +friendName);
friendIDsFromFB.Add(friendFBID);
}
//friendIDsFromFB.Add(AccessToken.CurrentAccessToken.UserId);
var query = Query.In("facebookID", BsonArray.Create(friendIDsFromFB));
//Debug.Log(query);
data = Mongo.Instance.players.Find(query).ToList();
}
Data Value for Key Method
private string getDataValueForKey(Dictionary<string, object> dict, string key) {
object objectForKey;
if (dict.TryGetValue(key, out objectForKey)) {
return (string)objectForKey;
} else {
return "";
}
}
Return Query Result
{
"_id" : ObjectId("XXXXXX"),
"facebookID" : "XXXXXXXXXXXXXX",
"name" : "John Doe",
"highScore" : 40501
}
Related
Everything works fine in debug mode but when we run it in release the ExtractToDirectory call fails.
Here is the function for reference. Just to make sure we are not doing anything weird.
private bool UnzipFiles()
{
bool toReturn = true;
try
{
UpdateStatus("Almost done...");
string file = Path.Combine (DownloadFolder, "ZipFile.zip");
if(System.IO.Directory.Exists(UnzippingDestinationFolder))
{
System.IO.Directory.Delete(UnzippingDestinationFolder, recursive:true);
}
System.IO.Compression.ZipFile.ExtractToDirectory(file, UnzippingDestinationFolder);
UpdateStatus("Finished!");
var files = System.IO.Directory.GetFiles(UnzippingDestinationFolder);
int m = 3;
}
catch (Exception e)
{
toReturn = false;
}
Finally, here is the exception we get.
System.NullReferenceException: Object reference not set to an instance of an object
at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00000] in <filename unknown>:0
at SharpCompress.Common.Zip.Headers.DirectoryEntryHeader.Read (System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0
at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0
at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0
at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[SharpCompress.Archive.Zip.ZipArchiveEntry].MoveNext () [0x00000] in <filename unknown>:0
at System.IO.Compression.ZipArchive.CreateZip (System.IO.Stream stream, ZipArchiveMode mode) [0x00000] in <filename unknown>:0
at System.IO.Compression.ZipArchive..ctor (System.IO.Stream stream, ZipArchiveMode mode, Boolean leaveOpen, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0
at System.IO.Compression.ZipFile.Open (System.String archiveFileName, ZipArchiveMode mode, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0
at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0
at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName) [0x00000] in <filename unknown>:0
at NewBaron.Screens.DownloadContentScreen.UnzipFiles () [0x00000] in <filename unknown>:0
A slight changes to Victor's solution. Not linking the SDKs generated an apk that was 53MBs. Too large for the play store's apk size limit.
I set the linking behavior to link SDK assemblies only and it brought the apk size down to 29MBs
Here is the updated window.
#mattewrobbinsdev's suggestion was exactly it. For future readers, here's the dialog in Xamarin Studio:
The following code compiles just fine in Visual Studio, but in Unity (4.6.x) it creates a compiler error:
public class ErrorTest
{
void DoSomething(bool a = true, bool f = true) { }
void DoSomething(int b, bool f = true) { }
public void SomeMethod()
{
DoSomething(f: false);
}
}
The call to DoSomething is what makes the compiler choke. The question is why, there's really no ambiguity.
The console output when Unity chokes like this:
Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Internal error
at Mono.CSharp.MethodGroupExpr.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase& method, System.Boolean& params_expanded_form) [0x00000] in <filename unknown>:0
at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0
at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0
There was/is apparently a bug where combining the use of namespaces and default parameters caused an internal error like this. It was allegedly fixed in 4.5, but from the comments it has been allegedly fixed before. You might try eliminating the namespace declaration in your class as an experiment to see if that bug is what you're experiencing.
I'm starting to use Optional parameters (as I came from java and haven't ever experimented with them before) and I'm running into the following issue:
Unhandled Exception: Mono.CSharp.InternalErrorException: Internal error
at Mono.CSharp.MethodGroupExpr.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase& method, System.Boolean& params_expanded_form) [0x00000] in <filename unknown>:0
at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0
at Mono.CSharp.New.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.If.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0
The code causing this issue is here:
Me = new UserAccount(
name: response["first_name"] as string,
age: DateToAge(response["birthday"] as string),
facebookID: response["id"] as string,
email: response["email"] as string,
gender: (response["gender"] as string == "male") ? 0 : 1
);
Where "response" is a Dictionary<string, object>
Dictionary<string, object> response = FacebookHelper.Deserialize(jsonString);
And the UserAccount class is here:
public class UserAccount {
public string SessionKey;
public string FacebookID;
public string Name;
public string Email;
public int Age;
public int Gender;
public GeoLocation Location;
public Texture Avatar;
public UserAccount(string name, int age, int gender, string email = "", GeoLocation location = null, string sessionKey = "", string facebookID = "", Texture avatar = null) {
Name = name;
Email = email;
Age = age;
Gender = gender;
Location = location;
SessionKey = sessionKey;
FacebookID = facebookID;
Avatar = avatar;
}
}
Could anyone point me in the correct direction of resolving this?
This is a genuine compiler error that's been there for a long time. Unity uses a fork of an old and buggy version of Mono. It happens because of named parameters. Personally, I was able to use named parameters sometimes, but in some cases it just crashed on a completely correct code. Unfortunately, the only advice I can give you is not to use named parameters with Unity Mono compiler.
Okay so I have came to an issue that I thought I fixed with a crappy rig and it failed in the long run, so I came to ask you guys the correct way to do it. Here is the issue I have, i'm making an application to filter out a certain type of email via POP3 (using the ActiveUp api) but I need it to have a constant connection to the POP3 server...this is what I have right now:
public static void Main (string[] args)
{
while(true)
{
POP3();
Console.Title = "Waiting for "+GetSubject+POST;
Thread.Sleep(5000);
}
}
public static void POP3()
{
Pop3Client pop3 = new Pop3Client();
try
{
pop3.ConnectSsl("pop.gmail.com",995,"", "");
if(pop3.MessageCount > 0)
{
int CurrentMessage = pop3.MessageCount;
ActiveUp.Net.Mail.Message message = pop3.RetrieveMessageObject(CurrentMessage);
if(message.Subject == GetSubject+POST)
{
Console.WriteLine("command reconized from {0}: {1}\n Sending responce now!",message.From.Email, message.Subject);
SMTP (message.From.Email, _message);
POST++;
pop3.Close();
}
}
else
{
Console.WriteLine("no mail found");
}
}
catch(Pop3Exception iex)
{
Console.WriteLine(iex);
pop3.Close();
}
}
Everything works perfect until about 10-20 minuets of it running I get kicked off of google's POP3 server and have to restart the application...Ill run the application now and reedit my question with the error...but until then can you guys please help me? Thanks!
Error:
nhandled Exception: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25
I am very new to Monotouch/iOS development. I'm using
==========
MonoDevelop 2.8.8.4
Installation UUID: 0d3db625-7df9-4282-9aa6-177c25a46d07
Runtime:
Mono 2.10.9 (tarball Tue Mar 20 15:31:37 EDT 2012)
GTK 2.24.10
GTK# (2.12.0.0)
Mono for Android not installed
Apple Developer Tools:
Xcode 4.2.1 (834)
Build 4D502
Monotouch: 5.2.10 (Evaluation)
==========
I am trying to serialize object to json string using Newtonsoft 3.5 all.
Very simple code but not working.. Can anybody can please help me ...
partial void Action_Clicked (MonoTouch.Foundation.NSObject sender)
{
myDTO test = new myDTO();
string teststring = ObjToJSON(test);
}
public string ObjToJSON(myDTO oObject) //Old function name is ObjToJSON_WithWrapper
{
string sJSON = "";
sJSON = Newtonsoft.Json.JsonConvert.SerializeObject(oObject);
return sJSON;
}
public myDTO JSONToObj(String JSONString) //Old function name is JSONToObjNew
{
myDTO deseri = JsonConvert.DeserializeObject<myDTO>(JSONString);
return deseri;
}
public class myDTO
{
public myDTO()
{
}
public string StringObject {get; set;}
}
Above is my simple test code but it's giving me error when it's run Newtonsoft.Json.JsonConvert.SerializeObject(oObject);
*** ERROR***
{System.TypeLoadException: A type load exception has occurred.
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[System.Type,System.Type].AddValue System.Type key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[System.Type,System.Type].Get (System.Type key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (ICustomAttributeProvider attributeProvider) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].AddValue (ICustomAttributeProvider key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Utilities.ThreadSafeStore`2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].Get (ICustomAttributeProvider key) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.CachedAttributeGetter`1[Newtonsoft.Json.JsonContainerAttribute].GetAttribute (ICustomAttributeProvider type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonContainerAttribute (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonObjectAttribute (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <filename unknown>:0
at JSONTest1.JSONTest1ViewController.ObjToJSON (JSONTest1.myDTO oObject) [0x00006] in /Users/developer/Projects/JSONTest1/JSONTest1/JSONTest1ViewController.cs:61
at JSONTest1.JSONTest1ViewController.Action_Clicked (MonoTouch.Foundation.NSObject sender) [0x00006] in /Users/developer/Projects/JSONTest1/JSONTest1/JSONTest1ViewController.cs:52 at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at JSONTest1.Application.Main (System.String[] args) [0x00000] in /Users/developer/Projects/JSONTest1/JSONTest1/Main.cs:17 }
You need this version of Newtonsoft for MonoTouch:
https://github.com/ayoung/Newtonsoft.Json