1

I am using (from Nuget packages) Ninject 2.2 and Fluent NHibernate 1.3 (NHibernate v3.2 under the hood) and I've hit a brick wall.

I am using Fluent config to point to my database, mappings etc:

var fluentConfig = Fluently.Configure()
    (MsSqlConfiguration.MsSql2008.DoNot.UseReflectionOptimizer()
    .ConnectionString(c => c.FromConnectionStringWithKey("ExampleDB")))
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ExampleMap>()
    .Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()))
    .ExposeConfiguration(x => x
                            .SetProperty("current_session_context_class", "web"))
    .ExposeConfiguration(BuildSchema);

The code works beautify on my local box, until I set < trust level="Medium" /> to mirror my hosting provider and then it starts to barf.

The problem line is the 2nd one in this code block

Bind<Configuration>().ToConstant(fluentConfig.BuildConfiguration());
Bind<ISessionFactory>().ToConstant(fluentConfig.BuildSessionFactory());
Bind<ISession>().ToMethod(x => GetRequestSession(x));

The exception I recieve: "...Request for the permission of type 'System.Security.Permissions.ReflectionPermission....failed"

Does anyone have any suggestions? My investigations thus far are turning up nothing but either out of date info based on older versions of Ninject and NHibernate or solutions that involve decompiling X to disengage Y...which I'd rather not do!

Greg
  • 31,180
  • 18
  • 65
  • 85
  • Between asking this question and now I have moved to a hosting provider that supports Full Trust. I would still like to know if there is a way to have FNHB in a Medium Trust env' though. – Greg May 11 '12 at 10:52

1 Answers1

2

Use the medium trust build instead of the version from NuGet: https://github.com/ninject/ninject/downloads

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98
  • That definitely helped, thank you. Swapping out the Ninject dll has allowed Ninject to operated correctly under Medium trust. (Fluent)NHibernate however is still throwing the same exception. I'm halfway there! – Greg Mar 01 '12 at 11:35