0

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 ---

Community
  • 1
  • 1
Norman
  • 705
  • 1
  • 10
  • 24

1 Answers1

1

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

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Are there any solutions to make this comparer work in a partial trust environment as well? Or switch to another simple 'alphabetic sorting' comparer if this could not run ? – Norman Nov 12 '10 at 14:24
  • You would have to implement `StrCmpLogicalW()` in managed code, which won't be easy. Fortunately, [there's hope](http://www.interact-sw.co.uk/iangblog/2007/12/13/natural-sorting). – Frédéric Hamidi Nov 12 '10 at 14:31
  • Thank you for all your help :) .. I started another question here: http://stackoverflow.com/questions/4165662/ any help would be appriciated. – Norman Nov 12 '10 at 14:56