.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Permissions.FileIOPermission

7 REPLIES 7
Reply
Message 1 of 8
pierreqc
548 Views, 7 Replies

Permissions.FileIOPermission

Hi,

I have a C# dll loaded in Autocad 2007 that calls System.IO.Directory.GetFiles(path, searchPattern).

It works fine on my development machine. It fails on the user's computer even though he has administrator right.

"Request for the permission of type 'System.Security.Permissions.FileIOPermission...' Failed"

So I made him try a test .exe application that calls Directory.GetFiles(path, searchPattern) and it works on his computer.

I understand that my dll is in a hosted environment so is there any setting that I must do on the end user machine or in my code to be able to call code that access the file IO ?

Thank you ! Message was edited by: PierreQC
7 REPLIES 7
Message 2 of 8
Mikko
in reply to: pierreqc

<CommandMethod("Myfiles")> _
Public Sub Myfiles()
For Each foundFile As String In My.Computer.FileSystem.GetFiles("c:\temp", FileIO.SearchOption.SearchAllSubDirectories, "*.dwg")
MsgBox(foundFile.ToString)
Next
End Sub

Works for me without doing anything to the users computer.
Message 3 of 8
Anonymous
in reply to: pierreqc

The key to your issue probably lies in the file path, which you did not say
what it is. A windows user/application obviously may or may not have access
to certain file/folder on a machine.

In you case, it seems a user cannot access a file/folder via AutoCAD. What
the file/folder is, it is local file/folder or network file/folder? The
administrator right the user has is local one or network domain one?

wrote in message news:5263393@discussion.autodesk.com...
Hi,

I have a C# dll loaded in Autocad 2007 that calls
System.IO.Directory.GetFiles(path, searchPattern).

It works fine on my development machine. It fails on the user's computer
even though he has administrator right.

"Request for the permission of type
'System.Security.Permissions.FileIOPermission...' Failed"

So I made him try a test .exe application that calls
Directory.GetFiles(path, searchPattern) and it works on his computer.

I understand that my dll is in a hosted environment so is there any setting
that I must do on the end user machine or in my code to be able to call code
that access the file IO ?

Thank you !

Message was edited by: PierreQC
Message 4 of 8
Anonymous
in reply to: pierreqc

I have had the same problem. When calling the system.io.directory.getfiles
with a file that is on a network or out of the scope of the executable then
you may get the error you described due to trusted assemblies. The runtime
security policy for the assembly may not have the correct permissions to
utilize the file that your program is trying to use. I was having a hard
time getting my code to execute properly from a network on various other
machines due to the difference in some users security policies for certain
domains located under the .net configuration in the control panel. It is
possible to configure everyone's runtime policy at login by deploying an
.msi file and that may fix your problem.

There are allot of trust options for managed code and I found it difficult
to find a work around without changing anyone's security settings to get it
to work. The work around that I used was to make sure that anyone who uses
one of my executables or dll files will have to first save it to their
computer. As long as everyone has the normal security settings to execute
code and read and write files within there own computer.

I wish I could be of more help but I am very new to .net and I have just
gone through the same issue you may be having. I did allot of GIS on the
subject and found that it is a topic that is hard to get help on. I have
also learned how powerful the managed assembly is when used in a trusted
environment. My guess is that it will inevitable lead to .net permission
nazi's (from power vacuum admins) and make software development even more
difficult to share, sell and configure.
--
CB



wrote in message news:5263393@discussion.autodesk.com...
Hi,

I have a C# dll loaded in Autocad 2007 that calls
System.IO.Directory.GetFiles(path, searchPattern).

It works fine on my development machine. It fails on the user's computer
even though he has administrator right.

"Request for the permission of type
'System.Security.Permissions.FileIOPermission...' Failed"

So I made him try a test .exe application that calls
Directory.GetFiles(path, searchPattern) and it works on his computer.

I understand that my dll is in a hosted environment so is there any setting
that I must do on the end user machine or in my code to be able to call code
that access the file IO ?

Thank you !

Message was edited by: PierreQC
Message 5 of 8
Anonymous
in reply to: pierreqc

One of Microsoft's goals with .NET was to create a more secure environment
so that the problems of VBA macro viruses, buffer overflows, etc. would be a
thing of the past.

Microsoft has also made many more things "secure by default", this can
result in security getting in the way more than it used to, but it helps
prevent unintended things from happening. Do you really fully trust
everyone with write access to a UNC share? If so--and I have write access
to your UNC share--then I could write a .NET ARX that reads email from your
disk and copies it to some other location.

This is going to get "worse" in Vista as most users won't (shouldn't) be
running with Administrator rights. Thankfully, Visual Studio 2005/.NET and
AutoCAD are pretty good in this area as you don't need to have Administrator
rights to develop a .NET ARX.

Dan

"CB" wrote in message
news:5263883@discussion.autodesk.com...
I have had the same problem. When calling the system.io.directory.getfiles
with a file that is on a network or out of the scope of the executable then
you may get the error you described due to trusted assemblies. The runtime
security policy for the assembly may not have the correct permissions to
utilize the file that your program is trying to use. I was having a hard
time getting my code to execute properly from a network on various other
machines due to the difference in some users security policies for certain
domains located under the .net configuration in the control panel. It is
possible to configure everyone's runtime policy at login by deploying an
.msi file and that may fix your problem.

There are allot of trust options for managed code and I found it difficult
to find a work around without changing anyone's security settings to get it
to work. The work around that I used was to make sure that anyone who uses
one of my executables or dll files will have to first save it to their
computer. As long as everyone has the normal security settings to execute
code and read and write files within there own computer.

I wish I could be of more help but I am very new to .net and I have just
gone through the same issue you may be having. I did allot of GIS on the
subject and found that it is a topic that is hard to get help on. I have
also learned how powerful the managed assembly is when used in a trusted
environment. My guess is that it will inevitable lead to .net permission
nazi's (from power vacuum admins) and make software development even more
difficult to share, sell and configure.
--
CB



wrote in message news:5263393@discussion.autodesk.com...
Hi,

I have a C# dll loaded in Autocad 2007 that calls
System.IO.Directory.GetFiles(path, searchPattern).

It works fine on my development machine. It fails on the user's computer
even though he has administrator right.

"Request for the permission of type
'System.Security.Permissions.FileIOPermission...' Failed"

So I made him try a test .exe application that calls
Directory.GetFiles(path, searchPattern) and it works on his computer.

I understand that my dll is in a hosted environment so is there any setting
that I must do on the end user machine or in my code to be able to call code
that access the file IO ?

Thank you !

Message was edited by: PierreQC
Message 6 of 8
pierreqc
in reply to: pierreqc

thank you,

What i don't understand is that when I execute the same code in a C# windows application on my client's computer, it works fine. But when It is in a C# dll "netloaded" in Autocad, the security doesn't allow me to run the Directory.GetFile method.

I don't know where to start, where to look.

Btw, The path is "C:\\toto" and the searchpattern is "*.txt".
Message 7 of 8
smcclure
in reply to: pierreqc

A good trick is to look in the SecurityException object - there is a lot of useful information there. For instance, there are collections that show the allowed permissions (GrantedSet) and refused permissions (RefusedSet). You can also find the URL of the assembly (if it is a network path, you need to modify the security settings as described above). You can also find the zone (helpful in figuring out what security settings are being applied to your code).

You should use the MMC snap-in on the client's computer to view the security settings, or if the MMC console is not available, the command line utility CASPOL is also available. Note that both of these utilities require adminisitrator level access. CASPOL and the snap-in will allow you to grant an application specific exception to the security policy on the computer if you so desire to allow file system access from whatever zone your code is being run under.

Note that for deployment, it may be useful to operate under the default security policy or use a tool like CASPOL in a script to change the security policy upon installation or using whatever scripting tool is available at the client's location.
Message 8 of 8
smcclure
in reply to: pierreqc

Hahaha, the default security policies will not even allow that now - all access to Microsoft Outlook programmatically must be actively approved by the user at runtime for a specified amount of time - no exceptions.

Apparently they are sick of viruses or something 🙂

-Scott

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost