- Home /
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?
Have you dropped the .dll
file into your project? Unity is prickly about the .NET project files, because it overwrites them often ins$$anonymous$$d of keeping your changes.
Like rutter said. Also RPCs cannot return anything; they also are unable to send anything except the following:
int
float
string
NetworkPlayer
NetworkViewID
Vector3
Quaternion
byte[]
@rutter where does the dll file need to be dropped? In looking at my project folders there doesn't seem to be any dll files anywhere.
@rutter Thanks, I did try what you suggested and Unity seemed to respond to the dll being in that folder although it is providing a different error now. I thought I would get both the external library AND unity compiled library into that Plugins folder before I decided it wasn't working but at the moment am having trouble finding the dll being created when I compile my code in $$anonymous$$onoDevelop. I'll come back once I have that.
Answer by omatase · Aug 09, 2014 at 08:24 PM
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.
I invest several hours in this issue before finding your post.
Thank you for saving me half the time that I may have invest!
I would like to state the same thing, thank you for posting your solution! :)
Your answer
Follow this Question
Related Questions
Add to .net Arrays 1 Answer
Open With... a Build Unity program 3 Answers
How and where is serialized data stored? 1 Answer
Loading Animations at Runtime? 0 Answers
SpeechRecognitionEngine.InstalledRecognizers() returns null within Unity. 3 Answers