Click here to Skip to main content
16,013,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Masters!
I try to understand my problem but finally after googling many times, i couldn't find out the solution.
My problem is:
I create a project using WCF service library template.
Add reference to Nhibernate dll.
Add using Nhibernate to the code
and try to add the following code
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
ISessionFactory sessionFactory = config.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();

Finally i build it with Error
The type or namespace name 'NHibernate' could not be found (are you missing a using directive or an assembly reference?)
Below is the code of my service class

MSIL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using NHibernate;
namespace WcfServiceLibrary1
{
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        public class Service1 : IService1
        {
                public string GetData(int value)
                {
                        return string.Format("You entered: {0}", value);
                }
                public CompositeType GetDataUsingDataContract(CompositeType composite)
                {
                        if (composite == null)
                        {
                                throw new ArgumentNullException("composite");
                        }
                        if (composite.BoolValue)
                        {
                                composite.StringValue += "Suffix";
                        }
                        return composite;
                }

                public void GetDataFromNhibernate()
                {
                        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
                        ISessionFactory sessionFactory = config.BuildSessionFactory();
                        ISession session = sessionFactory.OpenSession();
                }
        }
}


I don't know why. Can anyone help me?
THanks
Posted

Most probable reason is, the NHibernate.dll (That you have added in your project) is dependent on some other dll(s) which you need to add as reference in your project. As long as you don't add those dependent dlls in your project, the "The type or namespace name 'NHibernate' could not be found.." error message will continue to be shown.
 
Share this answer
 
Thanks for your answer on my question.
But because i've worked with Nhibernate many times, so i understand what you did mean. I also did that before i asked.
I also tried to create a project using WCF Service application template (not WCF Service library), added Nhibernate.dll and of course some other dlls, it's surprising that project just worked fine. It made me difficult to understand, so i tried and tried to find the reason why it happened, but uselessly. Finally i posted my question on this website, hoped i can get any responses.
Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900