为什么 ASP.NET-Core 应用程序在 MacOS 上部署时会收到错误消息 "Locking/unlocking file regions is not supported on this platform."?
Why could an ASP.NET-Core app get the error message "Locking/unlocking file regions is not supported on this platform." when deployed on MacOS?
我们的嵌入式数据库库使用FileStream.Lock(long, long)
方法来实现锁定。我们有一位客户在他们的小型 ASP.NET-Core Razor Page 应用程序中使用我们库的 .NET Standard 2.0 版本,他们报告说他们的应用程序在部署到 Mac[ 时出现 PlatformNotSupportedException "Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead." =26=](但部署在 Windows 上时不会)。我与客户确认过,它在 2013 Macbook Pro 上,在 APFS 上安装了最新的 Catalina。
当然,MacOS 并非真正不支持锁定文件区域——否则我们应该会收到更多的投诉!因此,我们想知道项目或安装中是否存在某些可能缺失或错误的东西来解释错误并有望得到纠正。还是我们可以 运行 进入比其他平台更严格的 MacOS 限制?我们确实在大多数文件末尾使用了一些大的特殊值(这在大多数情况下是合法的并且可以正常工作),但是我们已经限制这些值不超过带符号 Int32
的正范围,因为某些平台显然映射long
个参数转化为 int
个值。
有没有人遇到过这个错误并解决了问题?或者真的没有办法支持 Mac 上的 .NET 程序的文件区域锁定吗?
如果您检查 the source code,您会发现这 明确不受支持 。特定于版本的 FileStream.OSX.cs
文件明确抛出:
public partial class FileStream : Stream
{
private void LockInternal(long position, long length)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
private void UnlockInternal(long position, long length)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
}
GitHub 的好处是您可以使用 blame 找出该文件何时更改以及如何更改。
三年前(2017 年 2 月)的 commit comment 解释了为什么关闭此功能:
OSX doesn't support usage of both fcntl and flock. Since we're already using one in FileShare for the entire file, we cannot enable partial file locking like we do on other Unix platforms. The alternative is to throw a PNSE and suggest using FileShare on the whole file instead.
我们的嵌入式数据库库使用FileStream.Lock(long, long)
方法来实现锁定。我们有一位客户在他们的小型 ASP.NET-Core Razor Page 应用程序中使用我们库的 .NET Standard 2.0 版本,他们报告说他们的应用程序在部署到 Mac[ 时出现 PlatformNotSupportedException "Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead." =26=](但部署在 Windows 上时不会)。我与客户确认过,它在 2013 Macbook Pro 上,在 APFS 上安装了最新的 Catalina。
当然,MacOS 并非真正不支持锁定文件区域——否则我们应该会收到更多的投诉!因此,我们想知道项目或安装中是否存在某些可能缺失或错误的东西来解释错误并有望得到纠正。还是我们可以 运行 进入比其他平台更严格的 MacOS 限制?我们确实在大多数文件末尾使用了一些大的特殊值(这在大多数情况下是合法的并且可以正常工作),但是我们已经限制这些值不超过带符号 Int32
的正范围,因为某些平台显然映射long
个参数转化为 int
个值。
有没有人遇到过这个错误并解决了问题?或者真的没有办法支持 Mac 上的 .NET 程序的文件区域锁定吗?
如果您检查 the source code,您会发现这 明确不受支持 。特定于版本的 FileStream.OSX.cs
文件明确抛出:
public partial class FileStream : Stream
{
private void LockInternal(long position, long length)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
private void UnlockInternal(long position, long length)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
}
GitHub 的好处是您可以使用 blame 找出该文件何时更改以及如何更改。
三年前(2017 年 2 月)的 commit comment 解释了为什么关闭此功能:
OSX doesn't support usage of both fcntl and flock. Since we're already using one in FileShare for the entire file, we cannot enable partial file locking like we do on other Unix platforms. The alternative is to throw a PNSE and suggest using FileShare on the whole file instead.