English 中文(简体)
Lucene.NET in medium trust
原标题:

How do I make Lucene.NET 2.3.2 run in a medium trust environment? GoDaddy doesn t like it the way it is.

问题回答

I just recently struggled with this, and wanted to update this with a solution I got to work. I pulled down the latest code and built it myself so I could make changes if needed. In the SupportClass.cs file, starting at line 481 there is some code that verifies a file buffer has been flushed using unmanaged code.

        if (OS.IsWindows)
        {
            if (!FlushFileBuffers(fileStream.Handle))
                throw new System.IO.IOException();
        }
        else if (OS.IsUnix)
        {
            if (fsync(fileStream.Handle) != IntPtr.Zero)
            throw new System.IO.IOException();
        }
        else
        {
            throw new NotImplementedException();
        }

I commented out these lines and rebuilt the library and was able to run in medium trust. I ran locally in medium trust, as well as putting together a simple test app deployed to GoDaddy. I m not sure what the implications are of removing these lines. They appear to be duplicating the behavior of the fileStream.Flush() call that precedes this block, but I m not sure.

It should work. Lucene.NET was made compatible with a medium trust environment in commits 788091 and 788092, which went into the 2.3.2 release. You can verify this by looking at the history of the 2.3.2 tag with your favorite Subversion client.

I have just posted this question within the lucene users group and it has been recommended that you use the following:-

public static void Sync(System.IO.FileStream fileStream)
{
  if (fileStream == null)
    throw new ArgumentNullException("fileStream");

  //Will only compile with .net 4.0
  fileStream.Flush(true);
}

Quote from user group email:-

However, at the time, Lucene.NET was built on .NET 2.0 (IIRC) and didn t have access to the overload of the Flush method which was used to guarantee everything was flushed to disk:

http://web.archiveorange.com/archive/v/3k9XU33O4yJyW15fWfMd#MhNDlmKgnUj5fOj

Since you are now working in .NET 4.0, you should be able to replace the above code in SupportClass.cs





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签