Lucene.Net
  1. Lucene.Net
  2. LUCENENET-500

Lucene fails to run in medium trust ASP.NET Application

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Lucene.Net 3.0.3
    • Fix Version/s: Lucene.Net 3.0.3
    • Component/s: Lucene.Net Core
    • Labels:
      None

      Description

      I'm having trouble upgrading a web application running under medium trust from 2.9.4 to 3.0.3. Code that previously worked now throws a SecurityException.

      [SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
      Lucene.Net.Support.WeakKey`1..ctor(T key) +0
      Lucene.Net.Support.WeakDictionary`2.get_Item(TKey key) +113
      Lucene.Net.Util.DefaultAttributeFactory.GetClassForInterface() +178
      Lucene.Net.Util.DefaultAttributeFactory.CreateAttributeInstance() +95
      Lucene.Net.Util.AttributeSource.AddAttribute() +375
      Lucene.Net.Analysis.CharTokenizer..ctor(TextReader input) +126
      Lucene.Net.Analysis.WhitespaceTokenizer..ctor(TextReader in) +37

      1. VerifyableAssemblyNET35.zip
        866 kB
        Christopher Currens
      2. contrib.zip
        826 kB
        Christopher Currens

        Activity

        Hide
        Christopher Currens added a comment -

        Issue was in the WeakKey<T> class in WeakDictionary.cs. A generic wrapper for WeakReference was being used but was inheriting from WeakReference which requires UnmanagedCode security permissions. Removing the wrapper and doing casting instead fixes the permissions issue.

        Show
        Christopher Currens added a comment - Issue was in the WeakKey<T> class in WeakDictionary.cs. A generic wrapper for WeakReference was being used but was inheriting from WeakReference which requires UnmanagedCode security permissions. Removing the wrapper and doing casting instead fixes the permissions issue.
        Hide
        Joe Audette added a comment - - edited

        Hi,

        3.0.3 seems to work fine under .NET 4 medium trust but it is not working under .NET 3.5 medium trust
        Can someone fix this?

        [PolicyException: Required permissions cannot be acquired.]
        System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7610179
        System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57

        [FileLoadException: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600
        System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
        System.Web.Compilation.BuildManager.CompileResourcesDirectory() +31
        System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +304

        [HttpException (0x80004005): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
        System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8929163
        System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
        System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333

        Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387

        Thanks,

        Joe

        Show
        Joe Audette added a comment - - edited Hi, 3.0.3 seems to work fine under .NET 4 medium trust but it is not working under .NET 3.5 medium trust Can someone fix this? [PolicyException: Required permissions cannot be acquired.] System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7610179 System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57 [FileLoadException: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600 System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125 System.Web.Compilation.BuildManager.CompileResourcesDirectory() +31 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +304 [HttpException (0x80004005): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8929163 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333 Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387 Thanks, Joe
        Hide
        Christopher Currens added a comment -

        The Lucene.Net assembly is missing [assembly: AllowPartiallyTrustedCallers] in AssemblyInfo.cs. Adding it fixed the issue. I'll need to add the attribute to the contrib assemblies as well, I'm sure. If we want spatial to work, we'll need to do make sure its dependencies have this attribute as well.

        Show
        Christopher Currens added a comment - The Lucene.Net assembly is missing [assembly: AllowPartiallyTrustedCallers] in AssemblyInfo.cs . Adding it fixed the issue. I'll need to add the attribute to the contrib assemblies as well, I'm sure. If we want spatial to work, we'll need to do make sure its dependencies have this attribute as well.
        Hide
        Christopher Currens added a comment -

        Joe Audette – So I can be sure, can you post what it is you were trying to do when you ran into this issue? I didn't directly go into ASP.Net, instead I created a medium-trust domain, and I just want to verify that I'm getting the same issue as you are. Unfortunately, the exceptions that you listed aren't very helpful, when it comes to trying to nail this down.

        Can you either make a small set of code that reproduces the issue, or at least post the line of code where it is happening, as well as information about whatever IndexReader/Writer/Directory you're using and where the index is that you're trying to access. The more detailed information, the better I can be sure that we get this resolved.

        Thanks,
        Christopher

        Show
        Christopher Currens added a comment - Joe Audette – So I can be sure, can you post what it is you were trying to do when you ran into this issue? I didn't directly go into ASP.Net, instead I created a medium-trust domain, and I just want to verify that I'm getting the same issue as you are. Unfortunately, the exceptions that you listed aren't very helpful, when it comes to trying to nail this down. Can you either make a small set of code that reproduces the issue, or at least post the line of code where it is happening, as well as information about whatever IndexReader/Writer/Directory you're using and where the index is that you're trying to access. The more detailed information, the better I can be sure that we get this resolved. Thanks, Christopher
        Hide
        Joe Audette added a comment -

        Hi Christopher,

        Thanks for the quick attention on this. I use Lucene.NET for the search engine in mojoPortal CMS, in the latest release we upgraded to the latest Lucene.NET. I learned of this problem after our latest release when we got a bug report.
        https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=11371~1

        From the stacktrace of the error it is failing to load the assembly so it never got to mojoPortal code. The web app crashes completely as a result of the error, it doesn't run at all. We use the Simple FS Directory and the index files live in a folder below the root of the web app that is writable.

        I was able to reproduce the same result on my local machine by adding this in the Web.config file in the <system.web> section: <trust level="Medium" originUrl=".*" />

        Our .NET 4 package works fine under medium trust with Lucene.NET version 3.0.3.

        I've since been able to patch our package for .NET 3.5 to use the old version 2.1.0.3 of Lucene.NET that we were using before to solve the problem for our users. But it was an ugly fix with lots of conditional compilation so I'm going to be glad to have the official fix so I can clean that up.

        I'd be happy to test and confirm the fix if you want to make updated dlls available to me.

        Best Regards,

        Joe

        Show
        Joe Audette added a comment - Hi Christopher, Thanks for the quick attention on this. I use Lucene.NET for the search engine in mojoPortal CMS, in the latest release we upgraded to the latest Lucene.NET. I learned of this problem after our latest release when we got a bug report. https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=11371~1 From the stacktrace of the error it is failing to load the assembly so it never got to mojoPortal code. The web app crashes completely as a result of the error, it doesn't run at all. We use the Simple FS Directory and the index files live in a folder below the root of the web app that is writable. I was able to reproduce the same result on my local machine by adding this in the Web.config file in the <system.web> section: <trust level="Medium" originUrl=".*" /> Our .NET 4 package works fine under medium trust with Lucene.NET version 3.0.3. I've since been able to patch our package for .NET 3.5 to use the old version 2.1.0.3 of Lucene.NET that we were using before to solve the problem for our users. But it was an ugly fix with lots of conditional compilation so I'm going to be glad to have the official fix so I can clean that up. I'd be happy to test and confirm the fix if you want to make updated dlls available to me. Best Regards, Joe
        Hide
        Christopher Currens added a comment -

        @Joe - Thanks for the extra information. I've attached a version of lucene.net 3.5 that has the assembly attribute added to it. If you could check if that fixes it, that would be great.

        Show
        Christopher Currens added a comment - @Joe - Thanks for the extra information. I've attached a version of lucene.net 3.5 that has the assembly attribute added to it. If you could check if that fixes it, that would be great.
        Hide
        Joe Audette added a comment -

        Hi Christopher,

        It does not appear to be fixed using the new dll

        [PolicyException: Required permissions cannot be acquired.]
        System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7610179
        System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57

        [FileLoadException: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600
        System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
        System.Web.Compilation.BuildManager.CompileResourcesDirectory() +31
        System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +304

        [HttpException (0x80004005): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
        System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8929163
        System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
        System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333

        Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387

        Thanks,

        Joe

        Show
        Joe Audette added a comment - Hi Christopher, It does not appear to be fixed using the new dll [PolicyException: Required permissions cannot be acquired.] System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7610179 System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57 [FileLoadException: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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: Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600 System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125 System.Web.Compilation.BuildManager.CompileResourcesDirectory() +31 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +304 [HttpException (0x80004005): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from 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): Could not load file or assembly 'Lucene.Net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=85089178b9ac3181' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8929163 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333 Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387 Thanks, Joe
        Hide
        Christopher Currens added a comment -

        Joe Audette – That's good to hear, I thought that it might not (seemed a little too easy!) so I'm glad that it was easily verified to still not work. At least now, I can keep poking around to find why this is happening. I haven't seen any problems with loading the assembly in a medium trust environment, at least with the testing I've done, although I haven't been doing it in the ASP.Net environment. I'll see if I can reproduce it on my own, otherwise, I may just pull down the Mojo code and see if I can determine what's happening in the same environment.

        Show
        Christopher Currens added a comment - Joe Audette – That's good to hear, I thought that it might not (seemed a little too easy!) so I'm glad that it was easily verified to still not work. At least now, I can keep poking around to find why this is happening. I haven't seen any problems with loading the assembly in a medium trust environment, at least with the testing I've done, although I haven't been doing it in the ASP.Net environment. I'll see if I can reproduce it on my own, otherwise, I may just pull down the Mojo code and see if I can determine what's happening in the same environment.
        Hide
        Joe Audette added a comment -

        mojoPortal is a large app, its probably going to be easier for me to test it for you here. The code in our repository currently uses conditional compilation in a lot of places in the 2 main files where we use Lucene because of the syntax differences between the older version of Lucene.NET used by our 3.5 builds and the new version used in .NET 4 builds. I've kept a copy of those files modified to test with the dll you provided so I can restore them and try again with your next update. But the app fails to load its not failing at code that uses lucene, it never gets there and that code is not invoked just to run the app its only invoked at search time and when content is updated and we update the search index. Just having code that depends on lucene seems to be enough to break it in medium trust .NET 3.5.

        If you want to see the code to get an idea of what we are doing the 2 main files are:
        http://mojoportal.codeplex.com/SourceControl/changeset/view/2a64fd47ab2e#Web/Components/SearchIndex/IndexHelper.cs
        and
        http://mojoportal.codeplex.com/SourceControl/changeset/view/2a64fd47ab2e#Web/Components/SearchIndex/IndexWriterTask.cs

        We also use the highlighter and analyzers from contrib. By default we use the standardanalyzer but its configurable to use other ones.

        Just let me know if you get to a point where you need me to test again.

        Thanks,

        Joe

        Show
        Joe Audette added a comment - mojoPortal is a large app, its probably going to be easier for me to test it for you here. The code in our repository currently uses conditional compilation in a lot of places in the 2 main files where we use Lucene because of the syntax differences between the older version of Lucene.NET used by our 3.5 builds and the new version used in .NET 4 builds. I've kept a copy of those files modified to test with the dll you provided so I can restore them and try again with your next update. But the app fails to load its not failing at code that uses lucene, it never gets there and that code is not invoked just to run the app its only invoked at search time and when content is updated and we update the search index. Just having code that depends on lucene seems to be enough to break it in medium trust .NET 3.5. If you want to see the code to get an idea of what we are doing the 2 main files are: http://mojoportal.codeplex.com/SourceControl/changeset/view/2a64fd47ab2e#Web/Components/SearchIndex/IndexHelper.cs and http://mojoportal.codeplex.com/SourceControl/changeset/view/2a64fd47ab2e#Web/Components/SearchIndex/IndexWriterTask.cs We also use the highlighter and analyzers from contrib. By default we use the standardanalyzer but its configurable to use other ones. Just let me know if you get to a point where you need me to test again. Thanks, Joe
        Hide
        Joe Audette added a comment -

        codeplex site seems to have broken right after I posted those links, not sure whats up with that, hopefully it will heal itself soon.

        Show
        Joe Audette added a comment - codeplex site seems to have broken right after I posted those links, not sure whats up with that, hopefully it will heal itself soon.
        Hide
        Christopher Currens added a comment -

        Joe Audette, I was able to reproduce this bug and fix it. It turns out the assembly was requesting the SkipVerification security. For whatever reason, a few of the Lucene.Net projects were set to allow unsafe code, which can't run in a medium trust environment.

        I've atteched a new set of binaries to this issue. Can you test them and make sure they work for you?

        Thanks,
        Christopher

        Show
        Christopher Currens added a comment - Joe Audette , I was able to reproduce this bug and fix it. It turns out the assembly was requesting the SkipVerification security. For whatever reason, a few of the Lucene.Net projects were set to allow unsafe code, which can't run in a medium trust environment. I've atteched a new set of binaries to this issue. Can you test them and make sure they work for you? Thanks, Christopher
        Hide
        Joe Audette added a comment -

        Hi Christopher,

        I confirm the fix! But there is a similar error happening that seems to be coming from Lucene.Net.Contrib.Highlighter.dll

        I also use Lucene.Net.Contrib.Analyzers.dll but since we are configured for use of StandardAnalyzer by default I'm not sure if there is any problem with it. I haven't seen one so far.

        If I comment out the code that uses it to highlight search results, it works, but with that code included it gives a security error.

        [SecurityException: That assembly does not allow partially trusted callers.]
        mojoPortal.SearchIndex.IndexHelper.Search(Int32 siteId, Boolean isAdminContentAdminOrSiteEditor, List`1 userRoles, Guid featureGuid, DateTime modifiedBeginDate, DateTime modifiedEndDate, String queryText, Boolean highlightResults, Int32 highlightedFragmentSize, Int32 pageNumber, Int32 pageSize, Int32 maxClauseCount, Int32& totalHits, Boolean& invalidQuery) in c:_joe__projects__mojoportal_code\joedev\Web\Components\SearchIndex\IndexHelper.cs:1414
        mojoPortal.Web.UI.Pages.SearchResults.DoSearch() in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:268
        mojoPortal.Web.UI.Pages.SearchResults.SetupInternalSearch() in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:183
        mojoPortal.Web.UI.Pages.SearchResults.Page_Load(Object sender, EventArgs e) in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:120
        System.Web.UI.Control.OnLoad(EventArgs e) +99
        mojoPortal.Web.mojoBasePage.OnLoad(EventArgs e) in c:_joe__projects__mojoportal_code\joedev\Web\Components\mojoBasePage.cs:832
        System.Web.UI.Control.LoadRecursive() +50
        System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
        System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
        System.Web.UI.Page.ProcessRequest() +80
        System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
        System.Web.UI.Page.ProcessRequest(HttpContext context) +49
        ASP.searchresults_aspx.ProcessRequest(HttpContext context) +4
        System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
        System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

        Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387

        Thanks,

        Joe

        Show
        Joe Audette added a comment - Hi Christopher, I confirm the fix! But there is a similar error happening that seems to be coming from Lucene.Net.Contrib.Highlighter.dll I also use Lucene.Net.Contrib.Analyzers.dll but since we are configured for use of StandardAnalyzer by default I'm not sure if there is any problem with it. I haven't seen one so far. If I comment out the code that uses it to highlight search results, it works, but with that code included it gives a security error. [SecurityException: That assembly does not allow partially trusted callers.] mojoPortal.SearchIndex.IndexHelper.Search(Int32 siteId, Boolean isAdminContentAdminOrSiteEditor, List`1 userRoles, Guid featureGuid, DateTime modifiedBeginDate, DateTime modifiedEndDate, String queryText, Boolean highlightResults, Int32 highlightedFragmentSize, Int32 pageNumber, Int32 pageSize, Int32 maxClauseCount, Int32& totalHits, Boolean& invalidQuery) in c:_joe__projects__mojoportal_code\joedev\Web\Components\SearchIndex\IndexHelper.cs:1414 mojoPortal.Web.UI.Pages.SearchResults.DoSearch() in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:268 mojoPortal.Web.UI.Pages.SearchResults.SetupInternalSearch() in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:183 mojoPortal.Web.UI.Pages.SearchResults.Page_Load(Object sender, EventArgs e) in c:_joe__projects__mojoportal_code\joedev\Web\SearchResults.aspx.cs:120 System.Web.UI.Control.OnLoad(EventArgs e) +99 mojoPortal.Web.mojoBasePage.OnLoad(EventArgs e) in c:_joe__projects__mojoportal_code\joedev\Web\Components\mojoBasePage.cs:832 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242 System.Web.UI.Page.ProcessRequest() +80 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21 System.Web.UI.Page.ProcessRequest(HttpContext context) +49 ASP.searchresults_aspx.ProcessRequest(HttpContext context) +4 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387 Thanks, Joe
        Hide
        Christopher Currens added a comment -

        I noticed that Lucene.Net.Contrib.Analyzers.dll was set to allow safe code as well, but didn't realize you were using it, otherwise I would have included it. The other errors are related to the issue I initially found, where the DLLs were missing the AllowPartiallyTrustedCallers attribute.

        I've attached all of the contrib DLLs in a zip for .NET 3.5. I'm going to see what it might take to update the NuGet packages with these changes.

        Show
        Christopher Currens added a comment - I noticed that Lucene.Net.Contrib.Analyzers.dll was set to allow safe code as well, but didn't realize you were using it, otherwise I would have included it. The other errors are related to the issue I initially found, where the DLLs were missing the AllowPartiallyTrustedCallers attribute. I've attached all of the contrib DLLs in a zip for .NET 3.5. I'm going to see what it might take to update the NuGet packages with these changes.
        Hide
        Joe Audette added a comment -

        All seems to be working well now.
        Thanks a lot for your quick fix on this!

        Best Regards,

        Joe

        Show
        Joe Audette added a comment - All seems to be working well now. Thanks a lot for your quick fix on this! Best Regards, Joe
        Hide
        Christopher Currens added a comment -

        This was fixed last month, looks like I forgot to close the issue

        Show
        Christopher Currens added a comment - This was fixed last month, looks like I forgot to close the issue

          People

          • Assignee:
            Christopher Currens
            Reporter:
            Simon Svensson
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development