Author Topic: FileIOPermission error  (Read 3187 times)

0 Members and 1 Guest are viewing this topic.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
FileIOPermission error
« on: November 03, 2008, 01:10:14 PM »
Hi,

I'm still trying to learn a little C#.

I wanted to make a LISP function as getfiled but wich allows multiple selection using the Windows OpenFileDialog.

It works fine at home (XP & A2007), and I uploaded it on a French website to have some different release tests.
I had good returns excepted one who had an error :

Quote
_.netload Nom du fichier d'assemblage: GetFileLisp.dll
Commande: Échec de la demande d'autorisation de type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I tried to had some permission but cannot get it work with this guy.

Code: [Select]
using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using System.Security.Permissions;

namespace GetFileLisp
{
    public class myClass
    {
        /*
         * Fonction LISP getfiles
         * Ouvre une boite de dialogue permettant de choisir un ou plusieurs fichier
         * (getfiles repertoire filtre [multiple])
         *Exemple :
         * (getfiles "C:\\" "Dessin (*.dwg)|*.dwg|Tous (*.*)|*.*" T)
         */

        [LispFunction("getfiles")]
        public static ResultBuffer GetFileDialog(ResultBuffer buff)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ResultBuffer result = new ResultBuffer();

            try
            {
                if (buff == null)
                {
                    ed.WriteMessage("Erreur: nombre d'arguments insuffisants\n");
                    return null;
                }

                TypedValue[] args = buff.AsArray();

                if (args.Length < 2)
                {
                    ed.WriteMessage("Erreur: nombre d'arguments insuffisants\n");
                    return null;
                }

                if (args.Length > 3)
                {
                    ed.WriteMessage("Erreur: nombre d'arguments trop important\n");
                    return null;
                }

                if (args[0].TypeCode != (int)LispDataType.Text)
                {
                    ed.WriteMessage("Erreur: type d'argument incorrect: stringp {0}\n", args[0].Value);
                    return null;
                }

                if (args[1].TypeCode != (int)LispDataType.Text)
                {
                    ed.WriteMessage("Erreur: type d'argument incorrect: stringp {0}\n", args[1].Value);
                    return null;
                }

                bool mult = ((args.Length == 3) && (args[2].TypeCode != (int)LispDataType.Nil)) ? true : false;

                [color=#FF6600]//This was added to try get it work, but doesn't
                FileIOPermission permission = new FileIOPermission(PermissionState.None);
                permission.AllFiles = FileIOPermissionAccess.PathDiscovery; [/color]

                OpenFileDialog openDialog = new OpenFileDialog();

                openDialog.InitialDirectory = (string)args[0].Value;
                openDialog.Filter = (string)args[1].Value;
                openDialog.FilterIndex = 1;
                openDialog.Multiselect = mult;

                if (openDialog.ShowDialog() == DialogResult.OK)
                {
                    if (mult)
                    {
                        string[] fileNames = openDialog.FileNames;

                        foreach (string file in fileNames)
                        {
                            result.Add(new TypedValue((int)LispDataType.Text, file));
                        }
                    }
                    else
                    {
                        string file = openDialog.FileName;
                        result.Add(new TypedValue((int)LispDataType.Text, file));
                    }

                    return result;
                }
                else return null;
            }

            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.Message + "\n");
                return null;

            }
        }
    }
}

Here's the GetFileLisp.dll
Speaking English as a French Frog

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: FileIOPermission error
« Reply #1 on: November 03, 2008, 02:15:33 PM »
I don’t know, it works great here. Did someone try to load your DLL from a network drive or something?  :mrgreen:

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: FileIOPermission error
« Reply #2 on: November 03, 2008, 03:12:06 PM »
Thanks for your reply, Daniel.

Do you mean some network settings may prevent a prog to get filenames ?
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: FileIOPermission error
« Reply #3 on: November 03, 2008, 03:13:40 PM »
Thanks for your reply, Daniel.

Do you mean some network settings may prevent a prog to get filenames ?
I think he means that there is a problem when trying to run the dll from a network location, and dll.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: FileIOPermission error
« Reply #4 on: November 03, 2008, 03:53:40 PM »
Quote
I think he means that there is a problem when trying to run the dll from a network location, and dll.

I forgot to say that I purpose this guy to try also with a simple "Hello world lisp dll" and it worked fine. That made me think the problem was the filenames access.
Speaking English as a French Frog

sinc

  • Guest
Re: FileIOPermission error
« Reply #5 on: November 03, 2008, 03:59:26 PM »
From that error, it looks like he was trying to run the original DLL from someplace on a network server, while he may not have been doing that with your test program.  You may want to check again with him, and verify that he in fact does have both DLLs on his local machine.

If you want to run a DLL from a network server, you can do that if you authorize it with CASPOL, as with the instructions found on this page:

http://www.ejsurveying.com/SincpacC3D.aspx

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: FileIOPermission error
« Reply #6 on: November 03, 2008, 04:45:48 PM »
Thanks sinc,

We'll try this tomorrow, it's late here...
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: FileIOPermission error
« Reply #7 on: November 04, 2008, 03:04:04 AM »
Thanks all,

You were right, he runs the DLL from his local machine and it works fine.
I'm not comfortable with networks.

You're so good, I've so many to learn...
Speaking English as a French Frog