ReflectionPermission request failed

johny_bravo

Newcomer
Joined
Feb 18, 2006
Messages
2
Hi,

I'm writing an outlook 2003 plugin and encountered a problem.
I'm creating a new AppDomain in order to load an assembly into it. I don't
want to have this .dll loaded in CurrentDomain, so I can replace the file
after unloading additional domain. I'm using addDomain.Load(bytes[]) method
as it leaves the file untouched (that's what I read).
But the assembly is also being loaded to CurrentDomain. So I wanted to add
AssemblyResolve event as I read that returning Assembly from load causes
loading assembly into currentDomain.

Then I encoutered this:
Request for the permission of type
'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
At the top of the stack is:
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, ObjectDemand, IPermission permThatFailed).

As far as I understood some restrictions are missing - but I'm confused what
requires them, what kind and how to grant them.

If I can do it another way I'd love it :D if it works. Basically I want to
be able to replace the .dll file when outlook is running - I've got plugin
loading the main plugin logic from this .dll (assembly). I noticed that I can
load file as bytes, than load bytes as assembly and then the file is
untouched (say it's on c:\). But outlook also requires the same file to be in
the folder where outlook.exe resides and loads it when I load the 'c:\' one.
I want to use just one (no matter where it is supposed to be, by preferably a
dynamic location) - and in case of these two, they must be the same as then
there comes a version conflict.

This is what I use:

public static AppDomain Load(String iDllName, String iPath)
{
ApplicationDomain = AppDomain.CreateDomain("Domain",
AppDomain.CurrentDomain.Evidence);
ApplicationDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);
return ApplicationDomain;
}

static Assembly MyResolver(object sender, ResolveEventArgs args)
{
AppDomain domain = (AppDomain) sender;

byte[] rawAssembly = loadFile(@"c:\Synchronizer.dll");
return domain.Load(rawAssembly);
}

static byte[] loadFile(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] buffer = new byte[(int) fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();

return buffer;
}

I would be really, really greatful for any ideas as I spent 4 days on this
problem, and last 15 hours on this particular solution...

Kind regards,
johny
 
Back
Top