Interop with other C# assemblies

Is it possible to call a separately created C# assembly from Unity? I have an assembly I created for controlling a piece of hardware that was developed in C# using .NET 3.5 and I'd like to be able to call it from Unity. For example, when a users avatar collides with an object, I need to be able to call a function in the external library that will make the hardware do something. Is this possible? What is the easiest way to go about it?

The problem is because you're using a .Net 3.5 assembly, whereas Unity ships with a version of Mono that is equivalent to .Net 2.0. While Unity supports external assemblies via Mono, your assembly has dependencies on a more recent version (System.Runtime.Serialization 3.0, judging from your comment).

Have you read the documentation on plugin support?

http://unity3d.com/support/documentation/Manual/Plugins.html

Yeah. If it's a normal .NET assembly, just copy the .dll to anywhere in your Assets folder, and Unity will detect and use it. Also, when Unity generates the sln/csproj files, it's nice enough to adds the reference to that file for you too.

I assume you don't have the source... in that case, this is a longshot, but if you only need DataContractSerializer and maybe a few other things from System.Runtime.Serialization, you can try grabbing the S.R.S assembly from the Moonlight 2.0 beta. C# 3.5 compiles for the 2.0 CLR, so it theoretically could work.

Ok, so the best I can seem to do is this. My old dll (.NET 3.5) communicated with another process via WCF. It is possible to connect to a WCF server from .NET 2.0, but there are a few gotchas. The biggest problem for me is that it doesn't seem to work with named pipes. I can use basic HTTP for binding from .NET 2.0 instead, but I fear this may cause problems with our corporate firewall in some situations (from bitter experience). But at least it's functional on my computer at the moment. So my solution was to create a new .NET 2.0 dll, add my WCF service as a web service (after first changing it to include a BasicHTTPBinding in addition to the NetNamedPipeBinding endpoint) and Visual Studio creates a proxy class (as long as your server also published the necessary metadata). I can then access this from Unity (by adding the new dll to my assets) and it seems to work. This looks like it might be the only way to get Unity to talk to any .NET 3.5 code.

Okay, so it looks like I'm pretty much screwed at the moment, which is disappointing. I was gravitating towards Unity precisely because I could use my C# skills and hoped it would be fairly straight forward to integrate with code I already have.