C# windows应用商店应用程序中的等效安全文件句柄

C# windows应用商店应用程序中的等效安全文件句柄,c#,windows-store-apps,safefilehandle,C#,Windows Store Apps,Safefilehandle,我有一个作为Windows桌面应用程序编写的代码。我想将其转换为windows storeapp。但是,我找不到与SafeFileHandle等效的 这是代码 using Microsoft.Win32.Safehandles; using System; using System.IO; using System.Runtime.InteropServices; internal sealed class FileIO { internal const int FILE_ATTRIB

我有一个作为Windows桌面应用程序编写的代码。我想将其转换为windows storeapp。但是,我找不到与SafeFileHandle等效的

这是代码

using Microsoft.Win32.Safehandles;
using System;
using System.IO;
using System.Runtime.InteropServices;

internal sealed class FileIO
{
    internal const int FILE_ATTRIBUTE_NORMAL = 0x80;
    internal const int FILE_FLAG_DELETE_ON_CLOSE = 0x4000000;
    internal const int FILE_FLAG_OVERLAPPED = 0x40000000;
    internal const int FILE_FLAG_SEQUENTIAL_SCAN = 0x8000000;
    internal const int FILE_SHARE_DELETE = 4;
    internal const int FILE_SHARE_READ = 1;
    internal const int FILE_SHARE_WRITE = 2;
    internal const uint GENERIC_READ = 0x80000000;
    internal const uint GENERIC_WRITE = 0x40000000;
    internal const int INVALID_HANDLE_VALUE = -1;
    internal const int OPEN_ALWAYS = 4;
    internal const int OPEN_EXISTING = 3;

    [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);
}
Windows Storeapp中不支持Microsoft.Win32.Safehandles dll。 它给出错误“类型或命名空间名称Win32不存在于 命名空间“Microsoft”(是否缺少程序集引用?)

因此,SafeFilehandle会给出类似“找不到类型或命名空间名称‘SafeFilehandle’”的错误

你有什么建议吗


谢谢。

调用
CreateFile
有什么原因吗?为什么你不能使用
文件。创建
或类似的助手方法?@SriramSakthivel在我的脑海中处理替代流。@MichalHosala我猜也是:)但让我们看看是否是这样。应用商店运行在一个根本不同的底层平台上。这会产生很多后果,除了基于移除句柄的资源管理之外,您的CreateFile()调用永远不会成功。它被沙箱堵住了。出于相同原因,File.Create()不可用。避免问XY问题,始终解释您真正想要解决的问题。