Problem using Assembly.LoadFrom within a web service

S

surya

Hi,


I am using Assembly.LoadFrom within a web service to load assemblies from a

web site. This web site is in the same machine where I am running the web

service.

The Assembly.LoadFrom(httpsite) method throws a file not found exception.

I used the same code within a windows based application on the same machine

and it worked, so if the windows based application can load the assembly why

can't the web service find the same? I have been working on this problem

for a couple of days and can't figure out why it throws this exception. Is

this a security issue and if so why does it throw a file not found

exception?


Help is greatly appreciated.


Thanks in advance

Surya
 
J

Jan Tielens

From the documentation:
http://tinyurl.com/2r7g4
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003
family, .NET Compact Framework

..NET Framework Security:

a.. ReflectionPermission when invoked late-bound through mechanisms such
as Type.InvokeMember. Associated enumeration:
ReflectionPermissionFlag.MemberAccess.
b.. FileIOPermission for reading a URI that begins with "file://".
Associated enumeration: FileIOPermissionAccess.Read
c.. WebPermission for reading a URI that does not begin with "file://".
So it could be a security issue. Which OS are you using? xp, 2000
server/pro, 2003?

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
S

surya

Hi,

Below is the code i am using in both the web service as well as the
windows based application:

Assembly ass =
Assembly.LoadFrom("http://localhost/storage/shareassembly.dll");

Type cls1 = Type.GetType("ShareAssembly.Class1");

object obj1 = ass.CreateInstance("ShareAssembly.Class1");

System.Reflection.MethodInfo meth = cls1.GetMethod("Delete");

meth.Invoke(obj1,null);

This code works within a windows based/ console based application but
throws a File not found exception within a web service.

Within a web service, the code works if the assembly is loaded from a
local directory but fails if it is loaded from a url site or from a network
share.



Regards

Surya
 
S

surya

I am using a Windows 2000 server with IIS5.0.
I use the following code to load the assembly and then use it to create an
instance of a particular type.
Assembly ass =
Assembly.LoadFrom("http://localhost/storage/shareassembly.dll");
This line goes through if it is called within a windows/console based app
but fails only within a web service.



Regards
Surya
 
J

Jan Tielens

Ok, I've been able to reproduce this exception. It's a security issue, by
default the webservice can't download dll's (System.IO.FileLoadException:
HTTP download of assemblies has been disabled for this appdomain.).

Info I've found:
"HTTP download of assemblies has been disabled for this appdomain."

This error indicates that AppDomainSetup.DisallowCodeDownload has been set
on the domain. Setting his flag prevents any http:// download of assemblies
(or configuration files). ASP.NET sets this flag by default because the
internal usage of wininet/urlmon to download bits over http:// is not
supported under service processes.

So I don't know a solution for your problem... Is it possible to place this
dll in a file share instead of a website?
--
Greetz


Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
S

surya

Thanks very much for the information.
I get a FileNotFoundException but you get a FileloadException. I am using
..Net framework 1.0. R u using 1.1?

I need to download it from a http site as this would allow to overwrite
assemblies when they are in use by other applications. If I use a file
share, the loadfrom locks the assembly that is loaded and so does not allow
the assembly to be overwritten.

To get around the problem, I planned to load the files from a virtual
directory in the same machine. I also planned to write a listener on the
virtual directory folder (since the assemblies are on the same machine) to
check whether the assembly is overwritten and raise an event when the
assembly is overwritten. The applications that are using this assembly could
then decide to unload the appdomains that have loaded this assembly.


Thanks very much for helping me out on this issue.

Surya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top