Making a plugin using C#

Hello,

Is it possible to build a plug in using c# and use it from Unity script? I’ve built a test DLL in Visual Studio using C# OK but when I import it into Unity3D I get the following errors which I am not familliar with :frowning:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.TypeLoadException: Could not load type ‘System.Runtime.Versioning.TargetFrameworkAttribute’ from assembly ‘ClassLibrary1’.

at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Module,string,bool,bool)

at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in :0

at System.Reflection.Assembly.GetType (System.String name) [0x00000] in :0

at Mono.CSharp.RootNamespace.GetTypeInAssembly (System.Reflection.Assembly assembly, System.String name) [0x00000] in :0

at Mono.CSharp.RootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in :0

at Mono.CSharp.GlobalRootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in :0

at Mono.CSharp.Namespace.LookupType (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in :0

at Mono.CSharp.Namespace.Lookup (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in :0

at Mono.CSharp.TypeManager.CoreLookupType (Mono.CSharp.CompilerContext ctx, System.String ns_name, System.String name, Kind type_kind, Boolean required) [0x00000] in :0

at Mono.CSharp.TypeManager.InitCoreTypes (Mono.CSharp.CompilerContext ctx) [0x00000] in :0

at Mono.CSharp.Driver.Compile () [0x00000] in :0

at Mono.CSharp.Driver.Main (System.String[ ] args) [0x00000] in :0

I´m interested in this as well…
How does it work? Is the .dll forced to compile with Unity/Mono, or can I utilize a .dll with full access to (EDIT) C# 4.0 on a windows only setup?

OK So I worked out what the problem was. Turns out the problem was that I had the Target framework in Visual studio set to .Net 4.0 Unity 3 (I’m trialing the beta) needs the dll to be compiled for the .Net Framework 3.5 or less to work. Now that I’ve set the Target Framework to 3.5 I can compile my dll in visual studio and then drop it in the plugins folder in Unity. Unity converts it fine and I can then use it as follows:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using TestLibrary;

public class testDLL : MonoBehaviour {

	// Use this for initialization
	void Start () {
		runTestDLL();
	}
		
	void runTestDLL()
	{
		Debug.Log("Running Test DLL");
		TestClass client = new TestClass();
		Debug.Log(client.FooPluginFunction());
	}

}

where:
TestLibrary is my compiled dll
TestClass is a class inside the dll
FooPluginFunction() is a function inside the class

BTW, the reason I want to do this is that I need to interface Unity with some existing Com objects and I couldn’t work out how to do that from within Unity. So my plan is to build a wrapper in C#, from which it should be possible to interface with the Com objects, expose the funtionality I need in public methods in the wrapper, then import that into unity. So far I’ve got the plugin to reference the com objects I need and load into unity succesfully but I haven’t actually tried to access the functionality that I need from inside the com objects.

Wish me luck :slight_smile:

If anyone has any better ideas as to how to do this please let me know :slight_smile:

regards,

Tony

I wish you all the luck in the world! I´m also looking into the possiblities on COM interaction, so I hope you will post your progress :wink:
My feeling from reading loads of posts here is that we are locked to the Mono .NET wrapper even if we use an external assembly…
Can anyone confirm if this is correct.

Hello, guys. Anyone with a plugin using objective-c? Thanks