5

I've got to make a Unity script to import and export some 3D models. I'm trying to reference Servicestack.Redis from my script so I can talk to redis. It compiles fine but unity won't load the library.

I've copied the dll's from Build/Release/MonoDevelop/SericeStack.Redis.zip into my assets folder within unity, (is that correct?) I just got ServiceStack by cloning https://github.com/ServiceStack/ServiceStack.Redis

When Unity attempts to load the script it says

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

My code so far is this. It's an editor script. It just makes a window with a button and when the button is clicked it attempts to connect to redis on localhost and get a key

using UnityEngine;
using UnityEditor;
using System.Collections;
using ServiceStack.Redis;

public class MyWindow : EditorWindow
{

    // Add menu item named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    public static void ShowWindow()
    {
        //Show existing window instance. If one doesn't exist, make one.
        EditorWindow.GetWindow(typeof(MyWindow));
    }

    void OnGUI()
    {
        if (GUILayout.Button("Press to Rotate"))
        {
            ProcessAsset();
        }
    }

    void ProcessAsset()
    {
        using (var client = new RedisClient("localhost"))
        {
            client.Get ("hello");
        }
    }
}

I'm probably just not referencing the library correctly. I'm fairly new to compiled languages.

4

2 回答 2

1

我有一个类似的错误。但它没有任何自定义 dll。原因是我在代码中使用了Func 。Mono 不支持Func。我尝试下载 dll 的源代码,它们使用了很多 Func。因此,这可能是您收到该错误的原因。

于 2012-11-12T06:32:57.060 回答
1

我知道这有点旧,但它出现在我的搜索结果中。因此,对于遇到此问题的任何其他人,请确保您的 Unity 项目设置设置为.Net 2.0而不是.Net 2.0 Subset.

菜单可以找到File -> Build Settings -> Player Settings -> Optimization.

于 2014-07-30T13:54:55.483 回答