RavenDB EmbeddedDocumentStorage in Medium Trust

493 views Asked by At

I'm trying to use RavenDB in Medium Trust, I would like to try the embedded model, since the hosting (cheap) I use will not allow to install a service. My code to initialize is the following:

private void ConfigureStorage()
    {
        store = new EmbeddableDocumentStore();
        store.Configuration.DefaultStorageTypeName = "munin";
        store.Configuration.DataDirectory=Server.MapPath("$/App_Data");
        store.Initialize();
    }

that works in full trust, but in Medium it throws:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. with the following stack trace:

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.StubHelpers.StubHelpers.DemandPermission(IntPtr pNMD) +0
   Microsoft.VisualBasic.CompilerServices.NativeMethods.GlobalMemoryStatusEx(MEMORYSTATUSEX& lpBuffer) +0
   Microsoft.VisualBasic.Devices.InternalMemoryStatus.Refresh() +68
   Microsoft.VisualBasic.Devices.InternalMemoryStatus.get_TotalPhysicalMemory() +11
   Microsoft.VisualBasic.Devices.ComputerInfo.get_TotalPhysicalMemory() +49
   Raven.Database.Config.InMemoryRavenConfiguration.GetDefaultMemoryCacheLimitMegabytes() +301
   Raven.Database.Config.InMemoryRavenConfiguration.Initialize() +631
   Raven.Database.Config.RavenConfiguration.LoadConfigurationAndInitialize(IEnumerable`1 values) +311
   Raven.Database.Config.RavenConfiguration..ctor() +189
   Raven.Client.Embedded.EmbeddableDocumentStore.get_Configuration() +99
   Wine2.MvcApplication.ConfigureStorage() +84
   Wine2.MvcApplication.Application_Start() +84

Raven build is: Version 573

Are there some workaraound to make it working under medium trust, or is this scenario unsupported?

2

There are 2 answers

2
Ayende Rahien On BEST ANSWER

Under strict medium trust, RavenDB won't work. But there plenty of hosting companies that provide hosting where RavenDB does work, because they tweaked the permissions.

2
Leniel Maccaferri On

From my experience I just gave up trying to run the embedded store in Medium Trust. I was getting the same error described in your question.

To overcome this, you can try www.winhost.com as described here:

How can I run RavenDB in a shared hosting environment?

It has the so desired Full Trust Allowed which is something one should look for in the case of RavenDB to avoid the current security permissions problems...

NOTE: I just tried this host and can confirm that it works great with RavenDB in Full Trust... :-)