macos - 为什么在 MacOS 上部署 ASP.NET-Core 应用程序时会收到错误消息 "Locking/unlocking file regions is not supported on this platform."?

标签 macos asp.net-core .net-core razor-pages

我们的嵌入式数据库库使用FileStream.Lock(long, long)方法来实现锁定。我们有一位客户在他们的小型 ASP.NET-Core Razor Page 应用程序中使用我们的库的 .NET Standard 2.0 版本,他报告说他们的应用程序遇到 PlatformNotSupportedException“此平台不支持锁定/解锁文件区域。在而是整个文件。”在 MacOS 上部署时(但在 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找出该文件何时更改以及如何更改。

commit comment三年前(2017 年 2 月)解释了为什么此功能被关闭:

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.

关于macos - 为什么在 MacOS 上部署 ASP.NET-Core 应用程序时会收到错误消息 "Locking/unlocking file regions is not supported on this platform."?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60516874/

相关文章:

ios - Xcode 8 无法存档 "Command/usr/bin/codesign failed with exit code 1"

javascript - 浏览器链接 : Failed to invoke return value callback: TypeError: Cannot read property 'files' of null

c# - .net core 2 的编码问题

.net-core - 在 Blazor 中过滤分页列表

ios - SwiftUI:显示重复按钮且未触发操作的催化剂警报

macos - OS X 共享内存清理

objective-c - 如何检测 OS X 的 wifi/以太网/热点何时快速掉线?

c# - EF Core - 在事务中强制执行命令的优先级

c# - 在 asp.net core DI 中添加通用服务

c# - 已安装服务后如何从外部文件更改工作器服务间隔时间