Fixing build errors in Web Player caused by external libraries.

I am currently using Moq and a customized version of SharpUnit to perform unit testing in my game. Everything works great, the only problem is that when I switch to a Web Player build I get the following error.

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

If I remove Moq.dll and comment out all the references to it, the errors goes away. Is there anyway to get the Web Player to ignore the library and it’s references so I don’t have to delete the library and all the unit tests every time I want to build a Web Player version?

You should be able to do something using Conditional Compilation. Just surround the Moq code with conditional compilation so it doesn’t compile when building the web player version. I’m not sure what that will do with the moq.dll, but if all references to it are compiled out it shouldn’t make any attempt to load it.

So the solution I found for now is to just put all the testing code and libraries in the Editor folder. Not sure if it is the right answer, but since it is not actually part of the game and only intended to be used from the editor, it doesn’t need to be in with other game libraries.