Medium Trust
I cannot for the life of me, figure out how to make my fluent automappings run under a medium trust. I'm using the build 633.
It looks like I need to turn off lazy loading, and also turn off the Reflection optimizer, but I don't know how to do that in the fluent configuration.
Here is my configuration:
sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(cs => cs.FromConnectionStringWithKey("DreamLeash"))
.UseOuterJoin()
.ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"))
.Mappings(m => Configure(m))
.BuildSessionFactory();
And a method that I use for part of that:
private static MappingConfiguration Configure(MappingConfiguration mappingConfiguration)
{
mappingConfiguration.AutoMappings.Add(GetConventionMapping());
mappingConfiguration.FluentMappings.AddFromAssembly(Assembly.Load("DreamLeash.Data"));
return mappingConfiguration;
}
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Aaron Reel on 28 Mar, 2010 12:02 PM
I forgot some:
Support Staff 3 Posted by Paul Batum on 29 Mar, 2010 01:13 AM
I don't have much experience with medium trust but my understanding is that you can't use reflection, right? If so, there's no way that you'll be able to use automapping, and there's a definite possibility that fluent mapping won't work either.
However, there is a workaround - you don't really have to generate the XML at runtime. You could use a build task to execute FNH, export the mappings to xml and then feed that to NH at runtime.
4 Posted by Aaron Reel on 29 Mar, 2010 04:33 AM
I finally figured out what to do, and the auto mappings work fine. I hope that this will help other people...
The AutoMap must be done with at least this:
AutoMap.Assembly(Assembly.Load("DreamLeash.Model"))
.Conventions.Add(LazyLoad.Never());
Because the lazy loading will not work in the medium trust environment. And we must also add an nhibernate config section to the web.config with these attributes:
...
...
And define that thusly:
And we will be able to use Fluent, with automappings, in a medium trust environment like say... the cheapest hosting package offered by GoDaddy, which is a typical virtual shared hosting environment.
TAA DAAA!
Support Staff 5 Posted by Paul Batum on 25 Apr, 2010 02:01 PM
Cool. I guess medium trust isn't quite as restrictive as I thought. Thanks for the follow up, this is useful.
Paul Batum closed this discussion on 25 Apr, 2010 02:01 PM.
Aaron Reel re-opened this discussion on 27 Apr, 2010 03:41 PM
6 Posted by Aaron Reel on 27 Apr, 2010 03:41 PM
Ok, so please ignore everything I said above. I thought I was actually testing what I had said in a medium trust environment, and as it turned out, I wasn't actually accessing the database. Once I did access the database, it all blew up.
So, for anyone that doesn't know already, you CANNOT use fluent or the auto-mapping in a medium trust environment.
What you have to do to use NHibernate in a medium trust, is turn off all lazy loading, turn off the reflection optimizer, and use xml files. You can export fluent mappings to xml files on the build, and in that case you are using fluent for your development and xml files at run time. Bottom line though, xml files only when the app is running.
I apologize if anyone was lead astray by my silliness above.
Support Staff 7 Posted by Paul Batum on 29 Apr, 2010 06:45 AM
Thanks Aaron. I'll close this one off now.
Paul Batum closed this discussion on 29 Apr, 2010 06:45 AM.