the security issue comes up alot when a website is deployed to a public ISP. the ISP will not allow partially trusted code for security reasons. usually with local, or internal development this is not an issue.
NH uses proxies to manage lazy loading. The proxies are created using Castle's Dynamic Proxy. It's transparent to your code. DP allows you to create/alter functionality of an object at runtime. it gets into AOP. You can replace the DP usage by utilizing the proxy generator add- in. this is a post build (compile) event which would scan your NH configuration and create a compiled proxy class which NH can use. By using a console app to spike NH you can avoid the security exception because everything runs local to your account. where as with a web application you are running under a restricted account by default. On Mar 5, 9:39 am, tqwhite <[email protected]> wrote: > You guys are great. I really appreciate the help. > > 1) I have gotten past the mappings problem. I put a reference to the > assembly in the cfg file and have been able to make progress. I could > tell it worked because it complained that I had the wrong type > ("int32" doesn't work, "int" does) and I was able to fix it. > > 2) Your advice is good, Jason, and I have been following it, going > step by step over the last several weeks. C# is still a foreign tongue > and I'm still completely confused by strong typing, but MVC and I are > old friends (that's what we've been doing in the php world for a > while).I have no need (that I know about) for console apps but have > got my MVC functioning smoothly. Also, mbUnit. Also, JavascriptMVC. > > I have read like crazy searching for a solution to this trust issue > (I'm not lazing around in the hope that ssomeone will just solve my > problem, though I have hope ;-) ). Everything I have read so far seems > to want me to recompile some parts of nH but I will jettison it before > I do that. This project needs to be maintainable in the long run. I'm > not sure what static proxy means or what I am using for dynamic ones. > I guess this must be inside nH somewhere. I will look look look. > > Answer me this, please. The web tells me that this has been a problem > since at least 2005. What OS are you folks running on? I am under the > impression that W7 is not much different than Vista or Windows Server > as far as security goes. > > I remain lost on the Security Exception but, thanks again for your > help. > > tqii > > On Mar 5, 7:42 am, Jason Meckley <[email protected]> wrote: > > > you can also adjust your entity mappings like this > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > assembly="ExpressBook" > > namespace="ExpressBook.Services.BaseDataObjects"> > > <class name="StudentBase"> > > ... > > because you define the assembly and namespace in the root element you > > can then use the short name when defining your mappings. > > If you define the assembly in hibernate.config.xml, then you do not > > need to add the assembly like Harold demonstrated above. If you are > > not defining the assembly in the config file then the you need to add > > the assembly when you instantiate Nh configuration. > > > I'm not familiar with Windows 7 or IIS 7 but I have read about the > > medium trust issue. there is an NH add on to create static proxies > > (rather than dynamic proxies) which is where the medium trust issue > > occurs. I think there is a link on NHForge to this. > > > Since you are new to .net, C#, NH, and MVC I would recommend spiking > > examples independent of each other. Once you feel comfortable with the > > frameworks try integrating them together. for example: > > spike a vanilla MVC project and play around with it until you feel you > > understand how it works. > > spike a console application to experiment with NH > > spike a console application to experiment with C# symantics > > > then you can integrate NH into your MVC project. when you come across > > an error you will be able to rule out some causes because you have a > > better understanding of how each framework works. > > > On Mar 5, 2:36 am, Harold Wanyama <[email protected]> wrote: > > > > tqwhite like Diego said you need to set up your configuration(i havent > > > seen > > > u mention setting it up anywhere). This is such that nhibernate can be > > > able > > > to locate your mapping files(set as embedded resources) something of the > > > sort...... Configuration cfg = new Configuration(); > > > cfg.AddAssembly("assemblyName"). At least that IMO is the cause of all > > > your > > > problems. > > > > On Fri, Mar 5, 2010 at 6:48 AM, tqwhite <[email protected]> wrote: > > > > You obviously have it too good in Argentina. You're going to have to > > > > settle for my gratitude. > > > > > Your patient explanation put me on the right track. I couldn't get the > > > > addAssembly version to work, but putting the mapping clause into the > > > > config file worked great. I plowed through a couple of type issues and > > > > Voila!, Security Exception. > > > > > [SecurityException: That assembly does not allow partially trusted > > > > callers.] > > > > NHibernate.ByteCode.LinFu.ProxyFactory..cctor() +0 > > > > > I immediately went to my various bin directories and changed all of > > > > the downloaded files so they are not blocked. No dice. > > > > > I surfed the web and read that this is a common problem for > > > > nHibernate, that it requires full trust. I looked into my IIS7 setup > > > > and it is set to "Full (internal)". I changed it to High but it made > > > > no difference. > > > > > I googled about and found a lot of discussion of this problem. I added > > > > > <trust level="Medium" originUrl="" /> > > > > > to the config. And this > > > > > using System.Security; > > > > [assembly: AllowPartiallyTrustedCallers] > > > > > to the class that configures nHibernate. No improvement so I removed > > > > them. > > > > > I don't know how to make my copy of Windows 7 operate as "Full Trust", > > > > or honestly, what that means. > > > > > Any thoughts? > > > > > thanks, > > > > tqii > > > > > On Mar 4, 5:20 pm, Diego Mijelshon <[email protected]> wrote: > > > > > My kids might probably go to the public university, which is free in > > > > > Argentina, but thanks anyway. > > > > > > At some point in your code, you are creating a > > > > NHibernate.Cfg.Configuration > > > > > instance, from which you use BuildSessionFactory() to get the > > > > sessionFactory > > > > > you're using there. > > > > > You need to tell the configuration where to get the mappings from. > > > > > Since you already have the hbm.file(s) embedded in your assembly, you > > > > > can > > > > > either: > > > > > - use the <mapping assembly="Assembly name"/> in the hibernate.cfg.xml > > > > file > > > > > - call configuration.AddAssembly(assembly) with the appropriate > > > > > assembly > > > > > instance or name. > > > > > > Diego > > > > > > On Thu, Mar 4, 2010 at 20:11, tqwhite <[email protected]> wrote: > > > > > > First, tell me where your kids are going to college so I can start > > > > > > scholarships for them. I can't tell you how much I appreciate this > > > > > > help. > > > > > > > Also, I should note, so you can interpret my dopiness properly, that > > > > > > I'm new to C#, .NET, strongly typed languages and WIndows. I've > > > > > > been a > > > > > > php guy for the last decade, however. > > > > > > > I don't know how I am building my configuration. I have a working > > > > > > .NET > > > > > > MVC project. I referenced in nHibernate (and Lin Fu when I got an > > > > > > error requesting it). I grabbed hibernate.cfg.xml from the download > > > > > > and changed the database string. Is that the configuration you mean? > > > > > > > I checked my project's properties to make sure that I have the right > > > > > > assembly name. Is this what you are talking about:<hibernate-mapping > > > > > > xmlns="urn:nhibernate-mapping-2.2" assembly="ExpressBook" > > > > > > namespace="ExpressBook">? > > > > > > > I suspect that I am missing the meaning of your questions. Please > > > > > > ask > > > > > > me more. > > > > > > > thanks, > > > > > > tqii > > > > > > > On Mar 4, 4:54 pm, Diego Mijelshon <[email protected]> wrote: > > > > > > > How are you building your configuration? > > > > > > > More specifically, how are you adding the assembly? > > > > > > > > Diego > > > > > > > > On Thu, Mar 4, 2010 at 19:06, tqwhite <[email protected]> wrote: > > > > > > > > I've spent the last two days trying to get my first bit of > > > > nHibernate > > > > > > > > to work. I am in "No Persister" hell. > > > > > > > > > Following is everything I have relative to this problem (what > > > > > > > > I've > > > > > > > > tried, environment, file names, xml, classes, error text). > > > > > > > > > Please, for the love of all that is holy, help me!! > > > > > > > > > tqii > > > > > > > > > What I've tried: > > > > > > > > > I've moved the file around everywhere that makes sense. It is > > > > > > > > presently in the same directory as the class. > > > > > > > > I took out the class definition. Nothing changes at all. > > > > > > > > I inserted stupid assembly and namespace definitions. Nothing > > > > changes > > > > > > > > at all. > > > > > > > > I recreated my starter project a few times. Doesn't matter. > > > > > > > > All of the alternatives to "embedded resource" that seemed > > > > relevant. > > > > > > > > It is presently embedded. > > > > > > > > I changed the code to refer to a new class with a different name > > > > but > > > > > > > > left the hbm unchanged. Same error, different name. > > > > > > > > > Environment: > > > > > > > > > Windows 7 > > > > > > > > ASP.NET MVC > > > > > > > > ASP.NET 3.5 sp1 > > > > > > > > Visual Studio 2008 > > > > > > > > > File names: > > > > > > > > > In the same directory > > > > > > > > studentBase.cs > > > > > > > > studentBase.hbm.xml > > > > > > > > > Also, hibernate.cfg.xml is in the top directory of the project. > > > > > > > > I > > > > used > > > > > > > > the sample with no changes except the connection string. I think > > > > this > > > > > > > > is being found properly because I can induce errors by changing > > > > > > > > it. > > > > > > > > > StudentBase.hbm.xml: > > > > > > > > > <?xml version="1.0" encoding="utf-8" ?> > > > > > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > > > > > > > assembly="ExpressBook" namespace="ExpressBook"> > > > > > > > > <class name="ExpressBook.Services.BaseDataObjects.StudentBase, > > > > > > > > ExpressBook"> > > > > > > > > <id name="id" column="id" type="int32" unsaved-value="0"> > > > > > > > > <generator class="native"> > > > > > > > > </generator> > > > > > > > > </id> > > > > > > > > <property name="first" column="first" type="text" > > > > not-null="false"/ > > > > > > > > > <property name="last" column="last" type="text" > > > > not-null="false"/> > > > > > > > > </class> > > > > > > > > > </hibernate-mapping> > > > > > > > > > StudentBase.cs: > > > > > > > > > using System; > > > > > > > > using System.Collections.Generic; > > > > > > > > using System.Linq; > > > > > > > > using System.Web; > > > > > > > > > namespace ExpressBook.Services.BaseDataObjects > > > > > > > > { > > > > > > > > public class StudentBase > > > > > > > > { > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
