Required permissions cannot be acquired
-
I want to access a class (TestClass) that is in a given assembly(Test.dll) on my machine. I use activator : ObjectHandle objH=null; objH=Activator.CreateInstanceFrom(@"\\Daniel\SharedDocs\Test.dll","TestClass"); TestClass tc=(TestClass)objH.Unwrap(); MessageBox.Show(tc.GetCompName()); But I get this error : "Required permissions cannot be acquired." What should I do? Thanks, Daniel.
-
I want to access a class (TestClass) that is in a given assembly(Test.dll) on my machine. I use activator : ObjectHandle objH=null; objH=Activator.CreateInstanceFrom(@"\\Daniel\SharedDocs\Test.dll","TestClass"); TestClass tc=(TestClass)objH.Unwrap(); MessageBox.Show(tc.GetCompName()); But I get this error : "Required permissions cannot be acquired." What should I do? Thanks, Daniel.
You should not load the DLL from a network path... instead use a local copy. Or change the default security settings in "Control Panel".
-
You should not load the DLL from a network path... instead use a local copy. Or change the default security settings in "Control Panel".
The exception type is : System.Security.Policy.PolicyException I think it has somthing to do with SecurityPermission and ReflectionPermission...
-
The exception type is : System.Security.Policy.PolicyException I think it has somthing to do with SecurityPermission and ReflectionPermission...
Daniel Zaharia wrote: The exception type is : System.Security.Policy.PolicyException I think it has somthing to do with SecurityPermission and ReflectionPermission... No, it has something to do with the Policy!!! So either change your policy to allow executiong ffrom network shares or change the way you load your assembly!
-
You should not load the DLL from a network path... instead use a local copy. Or change the default security settings in "Control Panel".
I get the same error even if i try to load the assembly from the same directory with the executing assembly. objH=Activator.CreateInstanceFrom("Test.dll","TestClass");
-
The exception type is : System.Security.Policy.PolicyException I think it has somthing to do with SecurityPermission and ReflectionPermission...
You need to add a code group with a URL or Site membership condition with the necessary privileges (or simply FullTrust permissions) for the directory (or any parent directory) to allow execution from that directory. For example, using a URL membership condition, use file://MYSERVER/SHARE/* or something like that. Be sure to add the asterisk at the end as a wildcard unless you only want to apply the policy to only one assembly (which, of course, you should include the assembly name). You should read Understanding .NET Code Access Security[^] here on CodeProject for more information. It's a good read and a comprehensive resource of what you can find scattered throughout the .NET Framework SDK.
Microsoft MVP, Visual C# My Articles
-
You need to add a code group with a URL or Site membership condition with the necessary privileges (or simply FullTrust permissions) for the directory (or any parent directory) to allow execution from that directory. For example, using a URL membership condition, use file://MYSERVER/SHARE/* or something like that. Be sure to add the asterisk at the end as a wildcard unless you only want to apply the policy to only one assembly (which, of course, you should include the assembly name). You should read Understanding .NET Code Access Security[^] here on CodeProject for more information. It's a good read and a comprehensive resource of what you can find scattered throughout the .NET Framework SDK.
Microsoft MVP, Visual C# My Articles
Thanks! Daniel.