These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: App_Code assembly in ASP.NET 2.0
PostPosted: Sat Jul 30, 2005 5:52 pm 
I have placed User class from QuickStart tutorial in App_Code folder and User.hbm.xml too.

In my test page I wrote:
Code:
  NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("App_Code");


And I become Exception:

Exception Details: NHibernate.MappingException: No persisters for: User

Source Error:


Line 33:
Line 34: // Tell NHibernate that this object should be saved
Line 35: session.Save(newUser);
Line 36:
Line 37: // commit all of the changes to the DB and close the ISession

Does not ASP 2.0 compile Entity.hbm.xml files to App_Code assembly?


Top
  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 9:49 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Did you read this post:

NHibernate.MappingException: No persisters for

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Mapping Files, App_Code .Net 2.0
PostPosted: Mon Sep 05, 2005 9:18 pm 
Did you find an answer to this problem? I am having the same problem and can only get my code to work if I manually load the mapping files with a call to config.AddXmlFile using a hardcoded path to my mapping files.

Thanks

Steve


Top
  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 11:46 pm 
+1

I am having the same problem with:

Microsoft Visual Studio 2005
Version 8.0.50727.7 (RTM.050727-0700)
Microsoft .NET Framework
Version 2.0.50727

if I manually load the hbm.xml files (with config.AddXmlFile("fullpath\*.hbm.xml")) it works - otherwise I get:
NHibernate.MappingException: Unknown entity class:

I have put the hbm.xml files in the App_Code directory (not much choice in a Website project) and they are flagged as "include in project".


Top
  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 7:30 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
joelatty wrote:
[...] they are flagged as "include in project".

I assume that you meant "Embedded Resource"

Anyway, check the advises here:
NHibernate.MappingException: No persisters for
(set the DEBUG mode, check for typo, ...)

And you can use a tool like ILDAsm to inspect your assembly and make sure that the hbm.xml mapping files are here.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 11:06 pm 
Quote:
I assume that you meant "Embedded Resource"


I can't seem to find a way to set the build action to "Embedded Resource" in Visual Studio 2005 Website project. It is not under the file properties.


Top
  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 1:06 pm 
There is no longer an embedded vs linked option. They have removed that in favor of embedding everything in the App_Code folder. But the hbm.xml files do not show up in the App_Code assembly even when they are in the App_Code folder. This must be a bug.


Top
  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 11:31 am 
Newbie

Joined: Mon Sep 12, 2005 11:38 am
Posts: 3
have anyone get a solution to this problem. I want to use asp net 2 with nhibernate but it has this problem, it can't load the xml file into assembly.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 6:24 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
I was able to load the .hbm.xml files as a resource somehow. I forget exactly how. I think I iterated through the resources in the currently executing assembly. But it doesn't matter anyways.

Even when you do manage to load the .hbm.xml files in an ASP.NET 2.0 project, it won't work. The name of the assembly changes each time you recompile. :(

The simple solution to all of this is to keep your object model classes and related .hbm.xml files as a seperate class library project. You then add a project reference to your web project, and all is good. You leave the .hbm.xml files as embedded resources, since that still works with Class Library projects. It's a better development practice anyhow.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 12:10 pm 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
fbarberan wrote:
have anyone get a solution to this problem. I want to use asp net 2 with nhibernate but it has this problem, it can't load the xml file into assembly.


I don't think you are going to be able to do it using the App_Code directory. That is for source code that is compiled on the fly.

Add a class lib project to your solution. Put your domain object classess and mapping files in this project. Reference this project from your Web Site "project".

I'm not sure if you can do this if you are using Web Developer Express. (It is only for web sites.) If not you can use C#/VB Express to create and build your domain assembly. You can reference the DLL from your Web Site in VWD Express.

BOb


Top
 Profile  
 
 Post subject: I got mine working
PostPosted: Tue Nov 08, 2005 5:48 pm 
I took this suggestion, and put all our hbm.xml mappings as embedded resources ( Set the( properties) build action to embedded resource) into a .dll which is deployed with our website to a .bin directory.

there seemed to be a big problem with reading these embedded resources (it used to just work, when we were using nhibernate version 0.7?)

I had to write this code to get it working again,

Configuration cfg = new Configuration();
Assembly assm = System.Reflection.Assembly.GetExecutingAssembly();
ResourceManager Rm = new ResourceManager("",assm);
string [] names = assm.GetManifestResourceNames();
foreach (string name in names)
{
if(name.EndsWith("hbm.xml") )
{
Stream XmlInputStream = assm.GetManifestResourceStream( name );
XmlTextReader reader = new XmlTextReader(XmlInputStream);
cfg.AddXmlReader(reader);
}
}
factory = cfg.BuildSessionFactory();

There may be many better ways to do it...I just stopped on the first one that worked.


By the way, I have been using Nhibernate with asp.net 2.0 for about 10 months now, with very few issues.


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.