Icomparer 实现时出错。请帮忙!

发布于 2024-10-02 06:57:01 字数 2918 浏览 2 评论 0原文

我创建了一个数组排序器来对数组进行排序,就像在 DNN 模块中的 Win Explorer 中一样。正如预览问题的答案:

对文件夹名称数组进行排序,例如 Windows 资源管理器(按数字和字母顺序)- VB.NET

A用户每当运行该模块时都会收到以下错误(如下),我不是经验丰富的 ASP.NET 开发人员。这个错误是因为我在 IComparer 中使用了 StrCmpLogicalW 引起的,并且正在在不支持 StrCmpLogicalW 的平台上使用。或者是因为权限问题引起的。

非常感谢任何帮助,

非常感谢。

这是导致错误的排序器。

Public Class nvSorter
    Implements IComparer(Of String)

    Declare Unicode Function StrCmpLogicalW Lib "shlwapi.dll" ( _
        ByVal s1 As String, _
        ByVal s2 As String) As Int32

    Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements System.Collections.Generic.IComparer(Of String).Compare
        Return StrCmpLogicalW(x, y)
    End Function

End Class

这是异常堆栈跟踪:

InnerException:无法比较数组中的两个元素。

消息: DotNetNuke.Services.Exceptions.PageLoadException:无法比较数组中的两个元素。 ---|> System.InvalidOperationException:无法比较数组中的两个元素。 ---|> System.Security.SecurityException: System.Security.Permissions.SecurityPermission at Nukeville.Modules.SkinLab.View.nvSorter.Compare(String x, String y) at System.Collections.Generic.ArraySortHelper1.SwapIfGreaterWithItems(T[]键,IComparer1 比较器,Int32 a,Int32 b) 在 System.Collections.Generic.ArraySortHelper1.QuickSort(T[] 键,Int32 左,Int32 右,IComparer1 比较器)在 System.Collections.Generic.GenericArraySortHelper1.Sort(T[] keys, Int32 index, Int32 length, IComparer1 comparer) 第一个失败的权限类型是:System.Security.Permissions。 SecurityPermission 失败的程序集的区域为:MyComputer --- 内部异常堆栈跟踪结束 --- 位于 System.Collections.Generic.GenericArraySortHelper1.Sort(T[] 键、Int32 索引、Int32 长度、IComparer1 个比较器)位于 System.Array.Sort[T](T[] 数组,Int32 索引,Int32 长度,IComparer1 比较器)位于 System.Array.Sort[T](T[] 数组, IComparer1 比较器)在 Nukeville.Modules.SkinLab.View.GetNVFolder(String ParentName, String[] cf) 在 Nukeville.Modules.SkinLab.View.GetJavaFolderArrays(String RootPath) 在 Nukeville.Modules.SkinLab.View。 Page_PreRender(Object s, EventArgs e) 在 System.Web.UI.Control.OnPreRender(EventArgs e) 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web .UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI .Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Control.PreRenderRecursiveInternal() 在 System.Web.UI.Page .ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- 内部异常堆栈跟踪结束 ---

I created an array sorter to sort arrays like in Win Explorer in a DNN module. As in the answer to a preview question:

Sorting an array of folder names like Windows Explorer (Numerically and Alphabetically) - VB.NET

A user is getting the following error (below) whenever they run the module, I'm not a particularly seasoned ASP.NET developer. Is this error caused becuase I used StrCmpLogicalW in my IComparer and is being used on a platform that does not support StrCmpLogicalW. Or is it caused becuase of a permissions issue.

Any help is much appriciated,

Thanks a huge lot.

Here's the sorter that causes the error.

Public Class nvSorter
    Implements IComparer(Of String)

    Declare Unicode Function StrCmpLogicalW Lib "shlwapi.dll" ( _
        ByVal s1 As String, _
        ByVal s2 As String) As Int32

    Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements System.Collections.Generic.IComparer(Of String).Compare
        Return StrCmpLogicalW(x, y)
    End Function

End Class

And this is the Exception stack trace :

InnerException: Failed to compare two elements in the array.

Message:
DotNetNuke.Services.Exceptions.PageLoadException: Failed to compare two elements in the array. ---|>
System.InvalidOperationException: Failed to compare two elements in the array. ---|> System.Security.SecurityException: System.Security.Permissions.SecurityPermission at Nukeville.Modules.SkinLab.View.nvSorter.Compare(String x, String y) at System.Collections.Generic.ArraySortHelper1.SwapIfGreaterWithItems(T[] keys, IComparer1 comparer, Int32 a, Int32 b) at System.Collections.Generic.ArraySortHelper1.QuickSort(T[] keys, Int32 left, Int32 right, IComparer1 comparer) at System.Collections.Generic.GenericArraySortHelper1.Sort(T[] keys, Int32 index, Int32 length, IComparer1 comparer) The type of the first permission that failed was: System.Security.Permissions.SecurityPermission The Zone of the assembly that failed was: MyComputer --- End of inner exception stack trace --- at System.Collections.Generic.GenericArraySortHelper1.Sort(T[] keys, Int32 index, Int32 length, IComparer1 comparer) at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer1 comparer) at System.Array.Sort[T](T[] array, IComparer1 comparer) at Nukeville.Modules.SkinLab.View.GetNVFolder(String ParentName, String[] cf) at Nukeville.Modules.SkinLab.View.GetJavaFolderArrays(String RootPath) at Nukeville.Modules.SkinLab.View.Page_PreRender(Object s, EventArgs e) at System.Web.UI.Control.OnPreRender(EventArgs e) at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-10-09 06:57:01

这是一个安全问题。您不能 p/invoke StrCmpLogicalW() 来自 部分信任 ASP.NET 环境。

It's a security issue. You can't p/invoke StrCmpLogicalW() from a partial trust ASP.NET environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文