T
Thomas Jespersen
Hello
I have a project where I dynamically loads a DLL form the Internet (using
the Assembly.LoadFrom), which in turns loads another referenced DLL. Both
assemblies needs write access to the local Hard Drive. This actually works
on most machines, but on a clean Windows XP installation with only .NET 1.0
I get the "Execution permission cannot be acquired" error, when the second
assembly try's to write to the disk. Why is that, do I need to something
different in .NET 1.0 to grant full trust to the second assembly?
Note: In both situations I'm logged on with a user with Administrator
The Main of the .exe which is installed on the users hard drive looks
something like this (I removed a lot of the code to make it illustrate my
problem):
Public Class Main
Public Shared Sub Main()
Dim myAssembly As System.Reflection.Assembly
'This should make sure that the first assembly has full trust (this
works)
AppDomain.CurrentDomain.Evidence.AddHost(New
System.Security.Policy.Zone(System.Security.SecurityZone.MyComputer))
myAssembly =
System.Reflection.Assembly.LoadFrom("http://mysite.com/myAssembly.dll",
AppDomain.CurrentDomain.Evidence)
Dim updaterClass As Type = myAssembly .GetType("MyAssembly.MyClass")
Dim myMethodInfo As System.Reflection.MethodInfo =
updaterClass.GetMethod("MyMethod")
myMethodInfo.Invoke(updaterClass, New Object() {"c:\unziped",
{"c:\myzipfile.zip"})
End Sub
End Class
The first assembly (myAssembly.dll) has a direct VS.NET project reference to
the second assembly, but because both assemblies are located physically on
the Internet myAssembly calls Assembly.LoadFrom to indicate where the to
find the second assembly. Something like this:
Imports ICSharpCode.SharpZipLib
Namespace MyAssembly
Class MyClass
Public Sub MyMethod(ByVal destinitaionFolder As String, ByVal
zipedFilenameAs String)
Dim sharpZipLibAssembly As System.Reflection.Assembly
'This should reuses the trust of the current domain, which
already has full trust
sharpZipLibAssembly =
System.Reflection.Assembly.LoadFrom("http://mysite.com/ICSharpCode.SharpZipLib.dll,
AppDomain.CurrentDomain.Evidence)
'SharpZipLib has a direct reference, so the above line is only
to indicate where the assembly is located
Dim zipOutputStream As ZipOutputStream
zipOutputStream = New
ZipOutputStream(File.Create(FileSystemUtil.BuildPath(destinitaionFolder,
zipedFilename)))
....
End Sub
End Class
End Namespace
Any suggestions?
Thomas
I have a project where I dynamically loads a DLL form the Internet (using
the Assembly.LoadFrom), which in turns loads another referenced DLL. Both
assemblies needs write access to the local Hard Drive. This actually works
on most machines, but on a clean Windows XP installation with only .NET 1.0
I get the "Execution permission cannot be acquired" error, when the second
assembly try's to write to the disk. Why is that, do I need to something
different in .NET 1.0 to grant full trust to the second assembly?
Note: In both situations I'm logged on with a user with Administrator
The Main of the .exe which is installed on the users hard drive looks
something like this (I removed a lot of the code to make it illustrate my
problem):
Public Class Main
Public Shared Sub Main()
Dim myAssembly As System.Reflection.Assembly
'This should make sure that the first assembly has full trust (this
works)
AppDomain.CurrentDomain.Evidence.AddHost(New
System.Security.Policy.Zone(System.Security.SecurityZone.MyComputer))
myAssembly =
System.Reflection.Assembly.LoadFrom("http://mysite.com/myAssembly.dll",
AppDomain.CurrentDomain.Evidence)
Dim updaterClass As Type = myAssembly .GetType("MyAssembly.MyClass")
Dim myMethodInfo As System.Reflection.MethodInfo =
updaterClass.GetMethod("MyMethod")
myMethodInfo.Invoke(updaterClass, New Object() {"c:\unziped",
{"c:\myzipfile.zip"})
End Sub
End Class
The first assembly (myAssembly.dll) has a direct VS.NET project reference to
the second assembly, but because both assemblies are located physically on
the Internet myAssembly calls Assembly.LoadFrom to indicate where the to
find the second assembly. Something like this:
Imports ICSharpCode.SharpZipLib
Namespace MyAssembly
Class MyClass
Public Sub MyMethod(ByVal destinitaionFolder As String, ByVal
zipedFilenameAs String)
Dim sharpZipLibAssembly As System.Reflection.Assembly
'This should reuses the trust of the current domain, which
already has full trust
sharpZipLibAssembly =
System.Reflection.Assembly.LoadFrom("http://mysite.com/ICSharpCode.SharpZipLib.dll,
AppDomain.CurrentDomain.Evidence)
'SharpZipLib has a direct reference, so the above line is only
to indicate where the assembly is located
Dim zipOutputStream As ZipOutputStream
zipOutputStream = New
ZipOutputStream(File.Create(FileSystemUtil.BuildPath(destinitaionFolder,
zipedFilename)))
....
End Sub
End Class
End Namespace
Any suggestions?
Thomas