Nhibernate on winhost?

Discussion in 'Third-party applications' started by nhibernate, Oct 11, 2010.

  1. Can NHibernate be ran here? It needs reflection for HQL, which apparently isn't allowed. Or is this something I have to set in my config file?

    Here is the stack trace:
    PHP:
    [SecurityExceptionRequest for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
       
    System.Security.CodeAccessSecurityEngine.Check(Object demandStackCrawlMarkstackMarkBoolean isPermSet) +0
       System
    .Security.CodeAccessSecurityEngine.Check(CodeAccessPermission capStackCrawlMarkstackMark) +31
       System
    .Security.CodeAccessPermission.Demand() +46
       System
    .Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type ownerStackCrawlMarkstackMarkBoolean skipVisibility) +166
       System
    .Reflection.Emit.DynamicMethod..ctor(String nameType returnTypeType[] parameterTypesType ownerBoolean skipVisibility) +40
       NHibernate
    .Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod(Type returnTypeType[] argumentTypes) +108
       NHibernate
    .Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod(IGetter[] getters) +93
       NHibernate
    .Bytecode.Lightweight.ReflectionOptimizer..ctor(Type mappedTypeIGetter[] gettersISetter[] setters) +66
       NHibernate
    .Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer(Type mappedClassIGetter[] gettersISetter[] setters) +33
       NHibernate
    .Tuple.Entity.PocoEntityTuplizer.SetReflectionOptimizer() +35
       NHibernate
    .Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel entityMetamodelPersistentClass mappedEntity) +345
       NHibernate
    .Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass mappedEntityEntityMetamodel em) +357
       NHibernate
    .Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClassISessionFactoryImplementor sessionFactory) +3326
       NHibernate
    .Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClassICacheConcurrencyStrategy cacheISessionFactoryImplementor factory) +600
       NHibernate
    .Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClassICacheConcurrencyStrategy cacheISessionFactoryImplementor factoryIMapping mapping) +233
       NHibernate
    .Persister.PersisterFactory.CreateClassPersister(PersistentClass modelICacheConcurrencyStrategy cacheISessionFactoryImplementor factoryIMapping cfg) +68
       NHibernate
    .Impl.SessionFactoryImpl..ctor(Configuration cfgIMapping mappingSettings settingsEventListeners listeners) +1412
       NHibernate
    .Cfg.Configuration.BuildSessionFactory() +104
       FluentNHibernate
    .Cfg.FluentConfiguration.BuildSessionFactory() in FluentConfiguration.cs:93

     
  2. never mind, I figured it out. I set my trust level to low, saved it, then set it back to full in IIS manager. That's weird that I had to do that though.
     
  3. Ray

    Ray

    I've seen this happened a couple of times. Sometimes you need to set your trust level low, save it, then set it to High or Full and then save it again. It seems that IIS is not taking in the Trust level changes.
     
  4. Just an FYI

    I ran into a trust level issue the other day too -- drove me crazy for quite a while because it wasn't reported as a trust issue, but a 'failure to load' issue. It went somehting like this....
    ------

    I was developing a new site for a client that worked fine on my test server, and when I uploaded it to Winhost, I started getting the 'unable to load type errors'.

    After a few hours of narrowing it down, it turned out that the entity framework model I was using was OK until I added a partial class against the E.F. entity for some expanded properties and it started giving me an 'unable to load type' error & NOT a trust level error -- that threw me off the track to say the least.

    Anyway... After some dumping & tracing I noticed the trust level was reported as Medium --- WTF??

    I knew that I had already changed the trust level on the site to 'Full' through IIS Manager -- and it reported it as High -- but like you I changed it to medium & back to Full -- worked -- for a while.

    I don't know why (was too brain dead at the time to keep track of things -- just wanted it to work), but it stopped again -- maybe something in the builds reset it -- although I didn't think it was supposed to work that way, but I'm not a 'trust'-y guy to know for sure.

    Finally it ocurred to me to just put the @#$% <trust level="Full" /> in the web.config & I haven't had any problems since.

    As to the original cause -- the only thing I could think of was that since the E.F. itself was OK with medium trust - it loaded, but when it needed a 'sub-component' that required a higher trust level (reflection I suspect) the component couldn't load and so it was the 'unable to load error' that was reported, not a trust level error.

    Hope that helps somebody else.
     
    Last edited by a moderator: Oct 14, 2015
  5. Thanks for the info. I'm sure it will save someone else a lot of time.
     
  6. Hi,
    Please am using Nhibernate C#. How can i configure my application to run Nhibernate hosted on Winhost? I built my web app with Nhibernate, but when hosted, not working. Need help please
     
    Last edited by a moderator: Oct 14, 2015

Share This Page