1

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?

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • I'd try again with 616, I remember seeing Ayende saying he fixed some medium trusts issues in the past week. Also why munin? – Phil Jan 30 '12 at 14:09
  • @Phil thanks for help: Isn't munin the only available option in medium trust ? – Felice Pollano Jan 30 '12 at 14:13
  • This is also my doubt when contracting a hosting company... I asked them for a free period just to test and see if things work as expected! :] They'll get back. I hope they allow me to test it before contracting a plan. – Leniel Maccaferri Feb 02 '12 at 16:45

2 Answers2

4

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.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • 1
    It would be nice to know the way they tweak, BTW build 616 seems to be compilew w/o AllowPartiallyTrustedCaller – Felice Pollano Jan 30 '12 at 16:27
  • Well... I'm having this same problem in Medium Trust. I even tried the latest unstable build 1.0.638 of the embedded store. Same thing. :( To see the exception I get just access the site: http://schetine.siteprofissional.com/ Any thoughts Ayende? No way to overcome this? – Leniel Maccaferri Feb 03 '12 at 21:47
2

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... :-)

Community
  • 1
  • 1
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • The .NET web team is no longer supporting medium trust... so MVC as a whole might break. http://stackoverflow.com/questions/16849801/is-trying-to-develop-for-medium-trust-a-lost-cause – Eric Rohlfs Oct 04 '13 at 15:43
  • @EricRohlfs nice to know about this! :) Thanks for sharing the link. – Leniel Maccaferri Oct 04 '13 at 16:02