I am loading an assembly using Assembly.LoadFrom(fileName). When fileName is on the local machine, everything works fine. When, however, the identical file (and dependencies) are on a remote network share, I get a System.Security.SecurityException the moment I try to create a new SqlConnection from the remote assembly:
System.Security.SecurityException: Request for the permission of type
‘System.Data.SqlClient.SqlClientPermission, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
failed.
What’s the cure?
You could load the assembly as bytes and load it with
Assembly.Load(bytes), maybe this works.Or you give the application the requested permission.
Edit:
I made a little test and it worked for me. Here is some code:
Something important:
There may be files which do not have a matching name and file name, but you can resolve this by checking all files in folder with
AssemblyName.GetAssemblyName(file).