After importing the jabber-net dlls from here into my project and running
using UnityEngine;
using System.Collections;
using jabber;
using jabber.client;
using jabber.connection;
public class XMPP : MonoBehaviour {
jabber.client.JabberClient jC;
// Use this for initialization
void Start () {
jC = new JabberClient();
}
}
Unity complains with:
Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.TypeLoadException: Could not load type ‘jabber.connection.XmppStream’ from assembly ‘jabber-net, Version=2.1.0.710, Culture=neutral, PublicKeyToken=924c5b18328d6f09’.
I have read that others (a very select few) have managed to get jabber-net integrated with their Unity code. Could anybody shed some light on how this could be done or point me to an alternative library? I would very much like to be able to use XMPP in my project.
Thanks
Edit
Thanks @Calvin for providing your helpful response and helping me drill down to the problem.
Steps to resolution:
- Compile the dlls in monodevelop after stripping out System.Drawing and System.Windows.Form (Change build target to be library instead of executable)
- Import the dlls in the Plugins folder (not a random folder)
- Change the Unity build target to be Net 2.0 (not Net 2.0 subset) and instruct it to strip bytecode
- Delete the SystemAssemblies folder to force a recompile
Postmortem
And … this approach appears to ultimately fail. Compiling to ios seems to break the dependency chain with ExecutionEngineException: Attempting to JIT compile method ‘(wrapper managed-to-native) System.Threading.Interlocked:CompareExchange (jabber.protocol.ProtocolHandler&,jabber.protocol.ProtocolHandler,jabber.protocol.ProtocolHandler)’ while running with –aot-only.
I was just able to compile the 2005-jabber-net solution in MonoDevelop and add it to a Unity 3.5.6 project without Unity generating a compiler error.
The solution had references to System.Drawing and System.Windows.Forms, which Unity doesn’t support. I removed those, changed the compile target to “Library”, and copied the 2005-jabber-net.dll, netlib.Dns.dll, and zlib.net.dll into the Unity project.
Your sample code compiled and ran when attached to a GameObject, but I didn’t test further.
edit: Just realized this assembly may require Unity Pro, since .Net socket access is restricted in the free version of Unity.
double edit: I take that back, just checked their product comparison chart and now .Net sockets are listed as available in the free version of Unity.