5minutes2start 5minutes2start - 3 months ago 27
C# Question

Integrate nhibernate with Unity3D

I am trying to implement Nhibernate to my Unity3D project.

My main project is compiled to Unity 3.5 net full Base Class Libraries
My second project (the one with Nhibernate reference) is compiled to .Net Framework 3.5 (.dll file is deployed to Aseets/Plugins folder)
I am using Nhibernate 3.4.0.4000

Unity3D gives error:

"[...]
Could not load file or assembly 'NHibernate, Version=3.4.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies."

So I copy NHibernate.dll and Iesi.Collections.dll to Assets/Plugins folder as well.

But it produce another error:

"

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 :0

at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in :0

at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in :0

at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in :0

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

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

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

The class System.Configuration.IConfigurationSectionHandler could not be loaded, used in System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
The class System.CodeDom.Compiler.CompilerParameters could not be loaded, used in System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

"

What depends on IConfigurationSectionHandler and where can I find it?

thanks,

Answer

Put the compiled DLLs file in the Assets folder not the Assets/Plugins folder. If you are using version 3.4.0, before compiling, open Logging.cs you need and change baseDir string from string baseDir = AppDomain.CurrentDomain.BaseDirectory; to string baseDir = System.Environment.CurrentDirectory; in line 86. It worked for this person.

Also make sure to have the .NET database connector DLL(MySQL.Data.dll) in the Assets folder.

EDIT:

You must also change Api Compatibility Level from .Net 2.0 Subset to .Net 2.0 as noted by OP.