I have the following simple code:
using UnityEngine;
using System;
using System.Messaging;
using System.IO;
using RabbitMQ;
using Mono.Messaging;
using Mono.Messaging.RabbitMQ;
namespace NB.src.ui {
public class NBMessage {
public void Init() {
Message msg = new Message();//build pass
if(!MessageQueue.Exists(".\\myQueue"))//error
{
MessageQueue.Create(".\\myQueue");
}
}
I get the following errors:
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Messaging.MessageQueue' from assembly 'System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)
at System.MonoType.GetMethods (BindingFlags bindingAttr) [0x00000] in :0
at Mono.CSharp.MemberCache.AddMethods (BindingFlags bf, System.Type type) [0x00000] in :0
at Mono.CSharp.MemberCache.AddMethods (System.Type type) [0x00000] in :0
at Mono.CSharp.MemberCache..ctor (IMemberContainer container) [0x00000] in :0
at Mono.CSharp.TypeHandle..ctor (System.Type type) [0x00000] in :0
at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in :0
at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in :0
at Mono.CSharp.TypeManager.MemberLookup_FindMembers (System.Type t, MemberTypes mt, BindingFlags bf, System.String name, System.Boolean& used_cache) [0x00000] in :0
at Mono.CSharp.TypeManager.RealMemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in :0
at Mono.CSharp.TypeManager.MemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in :0
What might cause this and how do I solve it?
Unity does not share resources with Mono, so even if Mono has access to a library it does not mean that Unity also have acces to it. Unity strives to make your projects as light as possible, so you need to manually add the required dlls to your project.
One of these ways should work for you:
Way 1: Add specific libs to your Unity3d project
Step 1: Create a "Plugins" folder in the assets folder of your project.
Step 2: Copy the missing libraries (.dlls) you want from their folder: Path to unity\Unity\Editor\Data\MonoBleedingEdge\lib\mono\2.0 to the folder you created on step 1
*Also note that in such a way it is possible to add some .NET 3.5 and above functionality (I have used it successfully with System.Xml.Linq.dll and System.Linq.dll)
Way 2: Add a larger subset of Mono-supported 2.0 libraries to Unity:
I am not sure if this will work for the specific libraries you have mentioned but I've added it for the sake of completeness
Step 1: Menu > Edit > Project Settings > Player
Step 2: In the inspector window that appears open "Other Settings"
Step 3: under the "Optimization" label, change the "Api Compatibility Level" from ".NET 2.0 subset" to ".NET 2.0"
*Note that this still does not support all Mono 2.0 - but a larger subset of those.
Hope these help