Lucene.NET in medium trust

情到浓时终转凉″ 提交于 2019-12-08 09:39:15

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1837161/lucene-net-in-medium-trust

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!