Type or namespace not found

I have a rather large .Net assembly I’ve written for my game’s back-end. I recently switched to Unity for my game’s engine and am trying to make use of this back-end assembly for doing a lot of my data access and in-game formulations via RPC calls to a Unity server.

I have the server project created and it runs fine. I added the .Net assembly as a reference and rebuilt the file. Still everything seems fine. I then add a method that returns a type I created in this external assembly. Still, everything in Mono Develop builds without errors. The class name from my assembly is declared as public and is recognized by the editor and compiler. However, when I close Mono Develop and try to run my game I get this error:

The type or namespace name `Battleschool’ could not be found. Are you missing a using directive or an assembly reference?

I know what the error means, I just don’t know why Unity thinks there is a problem where Mono Develop doesn’t.

Here is the code in question:

    [RPC] Battleschool.Common.Entities.Contract.AccountDetails GetAccountDetails()
	{
		Battleschool.Common.Logic.GameDirector game = new Battleschool.Common.Logic.GameDirector();
		return game.GetAccountDetailsShallow(85);
	}

I would appreciate any help solving this issue.

– Update 1 –

I have done some additional research based on feedback primarily from @rutter and am now in a better place but still trying to resolve the same overall issue of using an external library with my Unity script code.

I built a new project with a single class and spent a few hours getting that new project to compile fine into Unity. The things I learned:

I have to use “Assets” > “Import New Asset” to bring the compiled dll into Unity. Doing this placed my dll in the Assets section of my code and also put a copy of the dll in the root of the script project, included in the project itself. I have confirmed that the dll had to be in both of these places or it would give an error.

Armed with that information I went back to my real-world use case and tried the same thing. When I choose “Assets” > “Import New Asset” and choose the dll for my .Net 3.5 assembly I now get this error:

“Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.”

Researching this online it seems as though some people have this error when they reference System.Web in their projects and removing the reference fixes the error. I didn’t have this referenced anyway but I went through all my references and removed all those that weren’t in use but the error still persists.

Thoughts?

The answer to this ended up begin what I already put in my update above. I’m copying it here too so it’s easier to see what fixed the problem.


I had to use “Assets” > “Import New Asset” to bring the compiled dll into Unity. Doing this placed my dll in the Assets section of my code and also put a copy of the dll in the root of the script project, included in the project itself. I have confirmed that the dll had to be in both of these places or it would give an error.


After I did this I got a new error (also mentioned above) but shown here as well.

“Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.”

That ended up being an entirely separate issue. Ultimately, fixing this problem turned out to take about 10 hours of my time so I thought I’d include it here for anyone else that might come across this unfortunate issue.

It ended up that the library I was importing into Unity had a single extension method defined somewhere deep in the code somewhere. Once I removed that extension method this error went away.