• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Sam JC · Apr 07, 2011 at 12:21 AM · setuplog4net

how to fix this strange error regarding NHibernate inside Unity?

Hi all,

I am trying to setup a Unity app to connect to a MySQL database via NHibernate. I added to the Assets/Libs the following DLLs, taken both from the official NHibernate 3.0 binaries and the Mono runtime GAC repository:

  • Antlr3.Runtime
  • Castle.Core
  • Iesi.Collections
  • log4net
  • mysql.data
  • NHibernate
  • NHibernate.ByteCode.Castle
  • Remotion.Data.Linq
  • System.Configuration
  • System.Data
  • System.Data.DataSetExtensions
  • System.Xml
  • System.Xml.Linq
  • an assembly with data objects suitable for NHibernate

I changed, in Player Settings, the API compatibility level from ".NET 2.0 Subset" to ".NET 2.0" to allow the project to use all assemblies referenced internally by the NHibernate dlls.

I use the following code at the beginning of the Start method of a C# script attached to the main camera of the scene:

// Configuring Log4Net XmlConfigurator.Configure(new FileInfo(@"log4net.config"));

     // NHibernate
     if (Log.IsDebugEnabled) {
         Log.DebugFormat("BaseDirectory[{0}] RelativeSearchPath[{1}]", AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath);
     }
     var cfg = new NHibernate.Cfg.Configuration();
     cfg.Configure();
     cfg.AddAssembly(typeof (User).Assembly);
     sessionFactory = cfg.BuildSessionFactory();

     var schema = new SchemaExport(cfg);
     schema.Create(true, false);

I have the log4net.config and the hibernate.cfg.xml in the root directory of the project, where they are visible and supposedly local for both the generated executable that is deployed there and the Unity3D IDE. But when starting my app, i get a strange error:

ArgumentNullException: Argument cannot be null.

Parameter name: type at System.Activator.CheckType (System.Type type) [0x00000] in <filename unknown>:0

at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0

at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0

at NHibernate.LoggerProvider.GetLoggerFactory (System.String nhibernateLoggerClass) [0x00000] in <filename unknown>:0 Rethrow as ApplicationException: Unable to instantiate: at NHibernate.LoggerProvider.GetLoggerFactory (System.String nhibernateLoggerClass) [0x00000] in <filename unknown>:0

at NHibernate.LoggerProvider..cctor () [0x00000] in <filename unknown>:0 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for NHibernate.LoggerProvider at NHibernate.Cfg.Configuration..cctor () [0x00000] in <filename unknown>:0 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for NHibernate.Cfg.Configuration at Main.Start () [0x00042] in D:\Projects\aa_ed\ZoneServer\Assets\Main.cs:36

(Filename: Assets/Main.cs Line: 36)

The problem lies in the following function inside the class NHibernate.LoggerProvider:

private static string GetNhibernateLoggerClass() { var nhibernateLogger = ConfigurationManager.AppSettings.Keys.Cast<string>().FirstOrDefault(k => NhibernateLoggerConfKey.Equals(k.ToLowerInvariant())); string nhibernateLoggerClass = null; if (string.IsNullOrEmpty(nhibernateLogger)) { // look for log4net.dll string baseDir = AppDomain.CurrentDomain.BaseDirectory; string relativeSearchPath = AppDomain.CurrentDomain.RelativeSearchPath; string binPath = relativeSearchPath == null ? baseDir : Path.Combine(baseDir, relativeSearchPath); var log4NetDllPath = Path.Combine(binPath, "log4net.dll");

             if (File.Exists(log4NetDllPath))
             {
                 nhibernateLoggerClass = typeof (Log4NetLoggerFactory).AssemblyQualifiedName;
             }
         }
         else
         {
             nhibernateLoggerClass = ConfigurationManager.AppSettings[nhibernateLogger];
         }
         return nhibernateLoggerClass;
     }

That ends returning null because both AppDomain.CurrentDomain.BaseDirectory and AppDomain.CurrentDomain.RelativeSearchPath are null probably. So after a day of research im stuck with this issue. Is there any possible workaround?

Thanks in advance.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by the_Simian · Dec 29, 2011 at 04:27 AM

check out how these guys are using nHibernate: http://www.cjrgaming.com/photon_mmo_development

Might help.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Character Customization Example: How do you set up the models? 2 Answers

Pick up Item 1 Answer

pass data between scene for game settings? 1 Answer

lighting setup - share some tricks and tips 1 Answer

How to make a setup for my game ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges