简体   繁体   English

得到了System.InvalidOperationException:方法失败,出现意外错误代码64

[英]Got System.InvalidOperationException: Method failed with unexpected error code 64

I am working on getting folder's permission before access in C# console application , the path of folder could be local of ftp.Same is working on my machine but when deploy at production server its start throwing error System.InvalidOperationException: Method failed with unexpected error code 64 . 我正在尝试在C#控制台应用程序中访问之前获取文件夹的权限,该文件夹的路径可能是ftp的本地文件。我的机器上正在运行该文件,但是在生产服务器上部署时,其开始抛出错误System.InvalidOperationException: Method failed with unexpected error code 64

The exact error receive by code is 通过代码收到的确切错误是

System.InvalidOperationException: Method failed with unexpected error code   64.
at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity..ctor(Boolean isContainer, String name, AccessControlSections includeSections, Boolean isDirectory)
at System.Security.AccessControl.DirectorySecurity..ctor(String name, AccessControlSections includeSections)
at UploadData.FolderManager.IsConfiguredFolderAccessible(String path, Folder folder)

The full code that thrown error is 引发错误的完整代码是

 private static void IsConfiguredFolderAccessible(string path, Folder folder)
    {
        // If the file can be opened for exclusive access it means that the file
        // is no longer locked by another process.
        try
        {
            if (!Directory.Exists(path))
            {
                LogHelper.Log(string.Format("Folder does not exist on given path {0}. Please re-create folder, grant permission and re-start the UPC utility. ", folder.Path), LogHelper.LogLevel.Error);
                MailComponent.SendMail(string.Format("Folder does not exist on given path {0}. Please re-create folder, grant permission and re-start the UPC utility.", folder.Path), "Folder does not exist");
                return;
            }
            else
            {
                var accessControlList = Directory.GetAccessControl(path);

                if (accessControlList == null)
                {
                    LogHelper.Log(string.Format("AccessControlList on Folder {0} are not defined", folder.ToString()), LogHelper.LogLevel.Error);
                    MailComponent.SendMail(folder.ToString(), "AccessControlList on Folder are not defined");
                }
                var accessRules = accessControlList.GetAccessRules(true, true,
                                            typeof(System.Security.Principal.SecurityIdentifier));

                if (accessRules == null)
                {
                    LogHelper.Log(string.Format("AccessRules on Folder {0} are not defined", folder.ToString()), LogHelper.LogLevel.Error);
                    MailComponent.SendMail(folder.ToString(), "AccessRules on Folder are not defined");
                }
                foreach (FileSystemAccessRule rule in accessRules)
                {
                    if ((FileSystemRights.Write & rule.FileSystemRights) != FileSystemRights.Write)
                        continue;

                    if (rule.AccessControlType == AccessControlType.Deny)
                    {
                        LogHelper.Log(string.Format("Access permission denied on Folder {0}", path), LogHelper.LogLevel.Error);
                        MailComponent.SendMail(folder.ToString(), string.Format("Access permission denied on Folder {0}", path));
                    }
                }
            }
        }
        catch (PrivilegeNotHeldException pv)
        {
            LogHelper.Log(string.Format("Access permission denied on Folder {0}, Error detail : {1}", path, pv.ToString()), LogHelper.LogLevel.Error);
            MailComponent.SendMail(pv.ToString(), string.Format("Access permission denied on Folder {0}", path));
            throw pv;
        }
        catch (IOException io)
        {
            LogHelper.Log(string.Format("Folder does not exist on given path {0}, Error detail : {1}", path, io.ToString()), LogHelper.LogLevel.Error);
            MailComponent.SendMail(io.ToString(), string.Format("Folder does not exist on given path {0}.Please re-create folder, grant permission and re-start the UPC utility.", path));
            throw io;
        }
        catch (Exception ex)
        {
            LogHelper.Log(string.Format("General error occured on Folder {0}, Error detail : {1}", path, ex.ToString()), LogHelper.LogLevel.Error);
            MailComponent.SendMail(ex.ToString(), "General error occured");
            throw ex;
        }
    }

The error is generated by a call to the native Windows GetSecurityInfo() function. 该错误是通过调用本机Windows GetSecurityInfo()函数生成的。 You can see this in the source code for the NativeObjectSecurity class. 您可以在NativeObjectSecurity类的源代码中看到它。 Error 64 or 0x40 in hex has the following definition in winerror.h : 十六进制错误64或0x40在winerror.h具有以下定义:

ERROR_NETNAME_DELETED

The specified network name is no longer available. 指定的网络名称不再可用。

So your problem is most likely related to accessing a folder across the network. 因此,您的问题很可能与通过网络访问文件夹有关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MSAL System.InvalidOperationException:CompactToken 解析失败,错误代码:80049217 - MSAL System.InvalidOperationException: CompactToken parsing failed with error code: 80049217 身份验证失败-System.InvalidOperationException - Authentication failed - System.InvalidOperationException 代码抛出System.InvalidOperationException - Code throws System.InvalidOperationException System.InvalidOperationException:LINQ 表达式....'无法翻译。 ASP.NET 6...方法“DecodeFrom64”的翻译失败 - System.InvalidOperationException: The LINQ expression.... 'could not be translated. ASP.NET 6 ...Translation of method 'DecodeFrom64' failed DropDownList 错误,System.InvalidOperationException - DropDownList Error, System.InvalidOperationException UITest失败,出现以下错误:“ SetUp:System.InvalidOperationException” - UITest failed with : “SetUp : System.InvalidOperationException” System.InvalidOperationException:'代码应该无法访问' - System.InvalidOperationException: 'Code supposed to be unreachable' System.InvalidOperationException:'在 ToastNotification UWP 中调用 LaunchUriAsync 时,在意外时间调用了一个方法 - System.InvalidOperationException: 'A method was called at an unexpected time when calling LaunchUriAsync inside ToastNotification UWP EF代码优先-System.InvalidOperationException - EF Code First - System.InvalidOperationException c# wpf 错误 (System.InvalidOperationException) - c# wpf error (System.InvalidOperationException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM