I can add to the equation that about 10 lines further down the code I
perform the following check
Dim UnmanagedPerm As SecurityPermission = _
New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
UnmanagedPerm.Demand()
Without any problems. I have disabaled the FileIO security check pending
some feedback, thus I know that this code is executed flawless =/
And if it is of any help, the code I'm working on is controlled by VSS.
//Andreas
"Andreas Håkansson" <andreas.hakansson@nospam.com> skrev i meddelandet
news:%23g9wlUWoEHA.3988@tk2msftngp13.phx.gbl...
[quoted text, click to view] > While working at a small application, and trying to be a good .net citizen
> I perform
> a check to see if the executing code has permission to work with files in
> a specific
> directory, like this
>
> Dim FilePerm As FileIOPermission = _
> New FileIOPermission(FileIOPermissionAccess.AllAccess,
> Path.GetDirectoryName(FileName))
> FilePerm.Demand()
>
> However, when the code hits the call to the Demand method it throws an
> ExecutionEngineException with the message
>
> "Unable to retrieve security descriptor for this frame."
>
> The application is a WinForm application and in the Main method I assign
> the
> current users principal to the current thread like this
>
> Shared Sub main()
>
> Dim WinUser As WindowsIdentity = _
> WindowsIdentity.GetCurrent()
> Dim WinPrincipal As New WindowsPrincipal(WinUser)
> System.Threading.Thread.CurrentThread.CurrentPrincipal =
> WinPrincipal
>
> Dim main As New MainForm
> Application.Run(main)
>
> End Sub
>
> Any ideas to the reason for this?
>
> //Andreas
>