Npgsql in Medium Trust

316 views
Skip to first unread message

Max Bündchen

unread,
Feb 11, 2015, 10:50:01 AM2/11/15
to npgsq...@googlegroups.com
We have a old (2011) Web Form application running at a hosting service on Windows 2003. Last friday they change the environment from Full Trust to Medium Trust. After that the application works for a few time and then freezes the IIS pool of the application. After many tests, including a new pool for the application, the techs of the hosting service identity the problem in the Npgsql (version 2.0).

The Npgsql 2.0 works in Medium Trust? Is there something extra required?

Shay Rojansky

unread,
Feb 11, 2015, 6:25:19 PM2/11/15
to Max Bündchen, npgsq...@googlegroups.com
I'm not aware of any specific issues Npgsql has with medium trust, but then we don't specifically test for that or have lots of experience with it. I've opened an issue for us to run regular tests with medium/low trust.

Regarding your specific problem, any sort of extra info would help. It sounds like the connection pool may be clogged up for some reason, a thread stack trace might shed some light on the issue, any chance that could be arranged?

On Wed, Feb 11, 2015 at 4:50 PM, Max Bündchen <maxbu...@gmail.com> wrote:
We have a old (2011) Web Form application running at a hosting service on Windows 2003. Last friday they change the environment from Full Trust to Medium Trust. After that the application works for a few time and then freezes the IIS pool of the application. After many tests, including a new pool for the application, the techs of the hosting service identity the problem in the Npgsql (version 2.0).

The Npgsql 2.0 works in Medium Trust? Is there something extra required?

--
You received this message because you are subscribed to the Google Groups "Npgsql Help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to npgsql-help...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/npgsql-help/686fa4c8-a814-4408-b094-4a1b64841b94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Francisco Figueiredo Jr.

unread,
Feb 11, 2015, 6:32:48 PM2/11/15
to Shay Rojansky, Max Bündchen, npgsql-help

I remember we had a problem with medium trust. I remember we fixed that by changing the setting I anthem assemblyinfo. I think this change was after 2.0 version.

Max, did you try using a new 2.1.x or even 2.2.x version and see if it works?

You shouldn't need to worry about compatibility as 2.1.x and 2.2.x should work just in as 2.0. You can try first 2.1.x and if it's OK, you can change to 2.2.4.

I hope it helps.

Max Bündchen

unread,
Feb 12, 2015, 5:33:03 AM2/12/15
to npgsq...@googlegroups.com
I don't have access to server logs, just the feedback of the hosting service.

Anyway, my project runs at .Net 3.5 and I just found that the Mono.Security 2.0.0 (used in the .Net version by Npgsql) can't run in Medium Trust.

It's simple to reproduce: Make a new Web Forms project targeting .Net 3.5, add Npgsql from Nuget (current version) and try to run. It will throw an exception.

Unfortunately I can't migrate to .Net 4 as in this version the problem do not occur.

System.Security.Policy.PolicyException

[PolicyException: Não é possível obter permissões obrigatórias.]
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7613891
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57

[FileLoadException: Não foi possível carregar arquivo ou assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' ou uma de suas dependências. Falha ao conceder solicitações de permissão mínima. (Exceção de HRESULT: 0x80131417)]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Não foi possível carregar arquivo ou assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' ou uma de suas dependências. Falha ao conceder solicitações de permissão mínima. (Exceção de HRESULT: 0x80131417)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +232
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +51
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Não foi possível carregar arquivo ou assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' ou uma de suas dependências. Falha ao conceder solicitações de permissão mínima. (Exceção de HRESULT: 0x80131417)]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Não foi possível carregar arquivo ou assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' ou uma de suas dependências. Falha ao conceder solicitações de permissão mínima. (Exceção de HRESULT: 0x80131417)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8995651
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333

Max Bündchen

unread,
Feb 12, 2015, 5:34:36 AM2/12/15
to npgsq...@googlegroups.com
I forget to mention that it's required to add <trust level="Medium"/> inside <system.web>.

Shay Rojansky

unread,
Feb 12, 2015, 8:27:16 AM2/12/15
to npgsq...@googlegroups.com
Thanks for the extra info, it's important to know this.

Later versions of Npgsql (try 2.2.4.1) no longer use Mono.Security for SSL by default (they use the built-in SSLStream instead). This means that by upgrading to the latest Npgsql your problem may very well go away - can you try this and let us know? Note that there were some significant (and breaking) changes since 2.0 so test carefully before deploying to production.

Regardless we also have an issue for the possibility of dropping Mono.Security altogether in Npgsql 3.0. See also discussion in #380.

Keep us posted,

Shay

Francisco Figueiredo Jr.

unread,
Feb 12, 2015, 11:44:25 AM2/12/15
to Shay Rojansky, npgsql-help

If Shay's suggestion doesn't work, I think another possibility would be to recompile the code after removing all code  references to mono.security.

I think this change isn't very complex.

It's not ideal, but could help you get your site working while you wait for the version 3 which won't have mono.security dependency.

I hope it helps.

--
You received this message because you are subscribed to the Google Groups "Npgsql Help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to npgsql-help...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages