Your problem is that you added permissions for the OpenFileDialog
but you didn't assign any FileIOPermission
so by nature the dialog wants some file access permissions. You can assign this permnission to your PermissionSet
object a couple different ways:
If you want unrestricted file open access within your OpenFileDialog
:
permSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
If you want to give only file open access to a specified path(s):
permSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, "path_name"));
With this type of permission you would also need to set the default directory of the OpenFileDialog
;
OpenFileDialog obj = new OpenFileDialog();
obj.InitialDirectory = "path_name_defined_in_permissions";
obj.ShowDialog();
You may also need to change the assembly name in "Step 4" to reflect the file extension:
Interface1 i1 =
(ClassLibrary1.Class1)domain.CreateInstanceFromAndUnwrap("ClassLibrary1.dll",
"ClassLibrary1.Class1");
I needed to make this change to get mine working, but that just may be due to the fact that I'm using a network folder for my development path. Hope that helps!