Asp.NET mapping by code error

141 views
Skip to first unread message

Mert Ece

unread,
Dec 5, 2011, 8:34:16 AM12/5/11
to nhu...@googlegroups.com

Hi,

 

I am trying to write a web application in ASP.NET using 3.2 mapping by code. I copied the same mappings and classes from my working winforms application but got the error below in mapping stage. Is there any specific configuration or something I have to do in web application in order nhibernate to run?

 

Code:

 

        var mapper = new ModelMapper();

        mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

        var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); //ERROR

        NhConf = ConfigureNHibernate();

        NhConf.AddMapping(mapping);

        SchemaMetadataUpdater.QuoteTableAndColumns(NhConf);

        SessionFactory = NhConf.BuildSessionFactory();

 

 

 

Server Error in '/07-RPD' Application.


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

 

Line 82:         mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

Line 83:

Line 84:         var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

Line 85:

Line 86:         return mapping;


Source File: c:\Users\Mert\Documents\Visual Studio 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs Line: 84

Stack Trace:

 

[NullReferenceException: Object reference not set to an instance of an object.]

   NHibernate.Mapping.ByCode.<>c__DisplayClass3.<CompileMappingFor>b__2(Type t) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:549

   System.Linq.Enumerable.All(IEnumerable`1 source, Func`2 predicate) +146

   NHibernate.Mapping.ByCode.ModelMapper.CompileMappingFor(IEnumerable`1 types) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:549

   NHibernate.Mapping.ByCode.ModelMapper.CompileMappingForAllExplicitlyAddedEntities() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:1771

   NHibernateHelper.GetMappings() in c:\Users\Mert\Documents\Visual Studio 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs:84

   NHibernateHelper.Setup() in c:\Users\Mert\Documents\Visual Studio 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs:95

   ASP.global_asax.Application_Start(Object sender, EventArgs e) in c:\Users\Mert\Documents\Visual Studio 2010\Projects\07-RPD\Global.asax:8

 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17020

Michele Lepri

unread,
Dec 5, 2011, 9:02:12 AM12/5/11
to nhu...@googlegroups.com
My 2 cents: do you have any classes defined in an empty namespace?


Il 05/12/2011 14:34, Mert Ece ha scritto:
> Hi,
>
> I am trying to write a web application in ASP.NET using 3.2 mapping by
> code. I copied the same mappings and classes from my working winforms
> application but got the error below in mapping stage. Is there any
> specific configuration or something I have to do in web application in
> order nhibernate to run?
>

> _Code:_
>
> _ _


>
> var mapper = new ModelMapper();
> mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
> var mapping =
> mapper.CompileMappingForAllExplicitlyAddedEntities(); //ERROR
> NhConf = ConfigureNHibernate();
> NhConf.AddMapping(mapping);
> SchemaMetadataUpdater.QuoteTableAndColumns(NhConf);
> SessionFactory = NhConf.BuildSessionFactory();
>

> _ _


>
> Server Error in '/07-RPD' Application.
>

> ------------------------------------------------------------------------
>
> /Object reference not set to an instance of an object./
>
> *Description: *An unhandled exception occurred during the execution of


> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>

> *Exception Details: *System.NullReferenceException: Object reference not


> set to an instance of an object.
>

> *Source Error:*


>
> Line 82:
> mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
> Line 83:
> Line 84: var mapping =
> mapper.CompileMappingForAllExplicitlyAddedEntities();
> Line 85:
> Line 86: return mapping;
>

> *Source File: *c:\Users\Mert\Documents\Visual Studio
> 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs*Line: *84
>
> *Stack Trace:*


>
> [NullReferenceException: Object reference not set to an instance of an
> object.]
>
>
> NHibernate.Mapping.ByCode.<>c__DisplayClass3.<CompileMappingFor>b__2(Type t)
> in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:549
>
> System.Linq.Enumerable.All(IEnumerable`1 source, Func`2 predicate) +146
>
> NHibernate.Mapping.ByCode.ModelMapper.CompileMappingFor(IEnumerable`1
> types) in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:549
>
>
> NHibernate.Mapping.ByCode.ModelMapper.CompileMappingForAllExplicitlyAddedEntities()
> in
> d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\ByCode\ModelMapper.cs:1771
>
> NHibernateHelper.GetMappings() in c:\Users\Mert\Documents\Visual
> Studio 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs:84
>
> NHibernateHelper.Setup() in c:\Users\Mert\Documents\Visual Studio
> 2010\Projects\07-RPD\App_Code\Persistence\NHibernateHelper.cs:95
>
> ASP.global_asax.Application_Start(Object sender, EventArgs e) in
> c:\Users\Mert\Documents\Visual Studio 2010\Projects\07-RPD\Global.asax:8
>
>
>

> ------------------------------------------------------------------------
>
> *Version Information:*Microsoft .NET Framework Version:4.0.30319;
> ASP.NET Version:4.0.30319.17020

--
http://michelelepri.blogspot.com/

Richard Wilde

unread,
Dec 5, 2011, 9:02:53 AM12/5/11
to nhu...@googlegroups.com

Try

 

mapper.AddMappings(typeof(<A_CLASS_THAT_INHERITS_CLASSMAPPING>).Assembly.GetTypes());  

 

Rippo

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Mert Ece

unread,
Dec 5, 2011, 3:11:30 PM12/5/11
to nhu...@googlegroups.com
Default vs 2010 web application did not create namespace for any of the classes, I created manually and worked like a charm. Thanks Michele saved me alot of time.

Reply all
Reply to author
Forward
0 new messages