Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: dustin1138 on October 19, 2014, 04:01:21 PM

Title: Unityscript with WP8 is producing errors
Post by: dustin1138 on October 19, 2014, 04:01:21 PM
I'm using Unityscript for my current game. I've done the standard thing of moving the TNet folder under plugins. I can successfully build iOS and Android versions. But the WP8 version kicks out the following errors at build time:

Assets/Plugins/TNet/Client/TNSerializer.cs(965,22): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?
Assets/Plugins/TNet/Client/TNSerializer.cs(972,25): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?
Assets/Plugins/TNet/Client/TNSerializer.cs(1405,49): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?

Any ideas on addressing these errors while keeping my code in Unityscript? I'm trying to avoid rewriting my local multiplayer code in C# and using SendMessage commands to share the info with the rest of the project.
Title: Re: Unityscript with WP8 is producing errors
Post by: MCoburn on October 20, 2014, 12:26:07 AM
You shouldn't put TNet under plugins. It's not a compiled DLL. Just leave TNet's folder under assets.
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on October 20, 2014, 12:39:19 PM
I'm quoting ArenMook on this thread, http://forum.unity3d.com/threads/released-tnet-tasharen-networking-framework.163681/page-2 (http://forum.unity3d.com/threads/released-tnet-tasharen-networking-framework.163681/page-2):
"It has been said that TNet is the easiest of the networking libraries to learn, so it's really up to you. And yes, it will work with UnityScript, but you will want to move its scripts to the Plugins folder, similar to NGUI."
Title: Re: Unityscript with WP8 is producing errors
Post by: MCoburn on October 20, 2014, 09:26:27 PM
Well, I stand corrected then.

Have you tried reimporting the latest package of TNet? Have you moved the TNet folder under Plugins or just TNet/Client into Plugins/TNet/Client ?
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on October 20, 2014, 10:35:07 PM
Yup, using the brand spanking new 2.0.1 version (which I upgraded to recently in the hopes that this issue might have been fixed).

I had moved the entire TNet folder under plugins. I tried your suggestion but I'm afraid that moving just the client folder under Plugins/TNet produced 51 errors of the "type or namespace name `xxx' could not be found" variety.

As I mentioned before, the frustrating thing is the fact that I'm good as gold on both Android and iOS with the TNet folder under the Plugins folder. It's only on WP8 that I'm getting the 'FieldInfo' not found issue.
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on October 21, 2014, 12:14:54 AM
The platform you are trying to use (WP8) doesn't support reflection the same way as others, so those parts of the code need to be inside "#if REFLECTION_SUPPORT" tags.
  1. #if REFLECTION_SUPPORT
  2.         static List<string> mFieldNames = new List<string>();
  3.         static List<object> mFieldValues = new List<object>();
  4.  
  5.         /// <summary>
  6.         /// Helper function that retrieves all serializable fields on the specified object and filters them, removing those with null values.
  7.         /// </summary>
  8.  
  9.         static void FilterFields (object obj)
  10.         {
  11.                 Type type = obj.GetType();
  12.                 List<FieldInfo> fields = type.GetSerializableFields();
  13.  
  14.                 mFieldNames.Clear();
  15.                 mFieldValues.Clear();
  16.  
  17.                 for (int i = 0; i < fields.size; ++i)
  18.                 {
  19.                         FieldInfo f = fields[i];
  20.                         object val = f.GetValue(obj);
  21.  
  22.                         if (val != null)
  23.                         {
  24.                                 mFieldNames.Add(f.Name);
  25.                                 mFieldValues.Add(val);
  26.                         }
  27.                 }
  28.         }
  29. #endif
  1.                         case 254: // Serialization using Reflection
  2.                         {
  3. #if REFLECTION_SUPPORT
  4.                                 // Create the object
  5.                                 if (obj == null)
  6.                                 {
  7.                                         obj = type.Create();
  8.                                         if (obj == null) Debug.LogError("Unable to create an instance of " + type);
  9.                                 }
  10.  
  11.                                 if (obj != null)
  12.                                 {
  13.                                         // How many fields have been serialized?
  14.                                         int count = ReadInt(reader);
  15.  
  16.                                         for (int i = 0; i < count; ++i)
  17.                                         {
  18.                                                 // Read the name of the field
  19.                                                 string fieldName = reader.ReadString();
  20.  
  21.                                                 if (string.IsNullOrEmpty(fieldName))
  22.                                                 {
  23.                                                         Debug.LogError("Null field specified when serializing " + type);
  24.                                                         continue;
  25.                                                 }
  26.  
  27.                                                 // Try to find this field
  28.                                                 FieldInfo fi = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  29.  
  30.                                                 // Read the value
  31.                                                 object val = reader.ReadObject();
  32.  
  33.                                                 // Assign the value
  34.                                                 if (fi != null) fi.SetValue(obj, Serialization.ConvertValue(val, fi.FieldType));
  35.                                                 else Debug.LogError("Unable to set field " + type + "." + fieldName);
  36.                                         }
  37.                                 }
  38. #else
  39.                                 Debug.LogError("Reflection is not supported on this platform");
  40. #endif
  41.                                 return obj;
  42.                         }
I'll make the changes locally and make sure they're in the next update, but until then -- just change them so you get up and running.

P.S. When putting TNet under Plugins, make sure that the Editor folder remains outside it.
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on October 21, 2014, 02:12:50 AM
Hey Aren,

Progress! Yes, the editor folder is indeed outside the Plugin folder. Your code helped me get past the WP8 FieldInfo issue. But now when I try to build the project I get this error:

Error building Player: Exception: Error: type `System.Runtime.Serialization.Formatters.Binary.BinaryFormatter` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at TNet.Serialization.
Error: type `System.Runtime.Serialization.Formatters.Binary.BinaryFormatter` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at System.Void TNet.Serialization::.cctor().
Error: method `System.Void System.Runtime.Serialization.Formatters.Binary.BinaryFormatter::.ctor()` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at System.Void TNet.Serialization::.cctor().
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on October 22, 2014, 05:56:09 AM
WP8 doesn't have a BinaryFormatter?
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on October 22, 2014, 05:04:11 PM
Apparently not:

"Binary Serialisation is not supported on Windows Phone (the supporting classes are missing on there)"
http://answers.unity3d.com/questions/678740/savingloading-data-to-windows-phone-8-1.html
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on October 23, 2014, 03:54:53 PM
Well, that means that you can't serialize anything custom on a WP8 device. Only built-in simple elements like float, int, Vector3, etc. That's severely limiting...
Title: Re: Unityscript with WP8 is producing errors
Post by: morty346 on November 02, 2014, 04:04:16 PM
So is there not a solution tot he BinaryFormatter issue then?
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on November 03, 2014, 07:05:26 AM
As I understand it it's missing altogether, so nope.
Title: Re: Unityscript with WP8 is producing errors
Post by: morty346 on November 04, 2014, 10:45:42 AM
Once you get around the binary issue there appears to be a whole slew of other issues, from asyncsockets to threads being used different in that version of .net. 

Trying to build against wp8.1 is even worse...

This is very unfortunate... wp8.1 would be a great platform to have supported!! and TNET is the only limitation not allowing it to happen
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on November 04, 2014, 11:04:20 AM
The issue lies in the fact that (as I understand it) Microsoft forced Unity to use their half-finished new .NET framework, which happens to be missing a lot of the functionality. If Unity could just stick to Mono, everything would be fine.
Title: Re: Unityscript with WP8 is producing errors
Post by: morty346 on November 08, 2014, 11:55:22 PM
So apparently there is a #define
#if NETFX_CORE/#endif,
that can surround anything that is unique to the wp .net framework

http://docs.unity3d.com/Manual/wp8-1-faq.html


I tried to surround it in the code around all threads,sockets and binary readers, and while it did appear it would work, there was too much cross class mangling going on and worked myself into a fun fix one error create 10 more paradigm and eventually gave up...

But if someone is willing to give it a shot... I think if they simply surround the items with the #define and build with the net core param on, we could have wp8.1 support!

Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on November 24, 2014, 05:17:58 AM
I just loaded up the brand new 2.0.2 version of TNet (which lists WP8 compile error fixes). But I'm still getting missing content errors (Unity version 4.5.2). Is there something I'm missing? This isn't a UnityScript/plugins folder issue like I mentioned before since I get the error even with just the plugin in an empty project. Here's the error:

Error building Player: Exception: Error: type `System.Net.Sockets.SocketOptionLevel` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void TNet.TcpProtocol::set_noDelay(System.Boolean).
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on November 25, 2014, 01:58:00 AM
You can pretty much comment out that function's contents or wrap it in a #define to get around it. What else is giving you trouble? I Can wrap it in #defines on my end but need to know what they are. I can't compile / test WP8.
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on November 25, 2014, 05:43:38 AM
Hey Aren. Do you not have a WP8 test unit? It seems like Microsoft would be happy to hook you up with one.

Here's the error list I came up with so far. I wrapped each with "#if !UNITY_WP8" checks in order to proceed. I stopped on the last one since it seems to encompass "static public string GetResponse (WebRequest request)" which I couldn't figure out how to wrap without breaking calls to it from other scripts.

TNTcpProtocol:
Exception: Error: type `System.Net.Sockets.SocketOptionLevel` doesn't exist in target framework.
Exception: Error: type `System.Net.Sockets.SocketFlags` doesn't exist in target framework.
Exception: Error: method `System.IAsyncResult System.Net.Sockets.Socket::BeginConnect(System.Net.EndPoint,System.AsyncCallback,System.Object)`
Exception: Error: method `System.Boolean System.Threading.WaitHandle::WaitOne(System.Int32,System.Boolean)
Exception: Error: method `System.Void System.Net.Sockets.Socket::EndConnect(System.IAsyncResult)`
Exception: Error: type `System.Net.Sockets.SocketFlags` doesn't exist in target framework
Exception: Error: method `System.Int32 System.Net.Sockets.Socket::EndSend(System.IAsyncResult)`
Exception: Error: method `System.Int32 System.Net.Sockets.Socket::EndReceive(System.IAsyncResult)`
Exception: Error: type `System.Net.Sockets.SocketFlags` doesn't exist in target framework.

TNTools:
Exception: Error: type `System.Net.NetworkInformation.NetworkInterface` doesn't exist in target framework.
Exception: Error: type `System.Net.Dns` doesn't exist in target framework.
Exception: Error: method `System.String System.Net.WebClient::DownloadString(System.String)` doesn't exist in target framework.
Exception: Error: method `System.Net.WebResponse System.Net.WebRequest::GetResponse()` doesn't exist in target framework.
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on November 26, 2014, 09:17:54 PM
Might be easier if you just sent me the updated file(s) so I can have a look. In regards to GetResponse: what's the issue with it? All it does is checks a web request for a response.

And nope, I don't have a WP8 unit.
Title: Re: Unityscript with WP8 is producing errors
Post by: dustin1138 on November 27, 2014, 01:04:11 AM
Hey Aren,

I PM'd you.

Thanks,
Dustin
Title: Re: Unityscript with WP8 is producing errors
Post by: smuttlegiaco on February 12, 2015, 04:08:36 AM
while searching for a solution to our current problem, I stumbled over this thread. dustins problems are our problems at the moment, so I wanted to ask if there is any workaround available? thanks!
Title: Re: Unityscript with WP8 is producing errors
Post by: ArenMook on February 13, 2015, 09:16:51 AM
In short, WP8/WSA doesn't support .NET sockets the same way every other platform does. The only work-around that was established in this thread was to basically disable TNet's code on those platforms, making it possible to compile but also completely disabling networking.
Title: Re: Unityscript with WP8 is producing errors
Post by: smuttlegiaco on February 13, 2015, 09:48:38 AM
sucks!

thanks for the answer nontheless.