Can't load a file from a dll under ASPX pages

P

Plon Plon

Hi all,

I currently have a problem that looks too strange for me, can someone
help me?

I'm running an ASPX page that calls a C# component (DLL), and this DLL
works with an XML file.
I've placed the XML file and the C# component in a directory (i can't do
it different, and the installation path can be changed at each
installation)), and the component loads the XML by getting the
"location" property on the assembly object:

Assembly ca = typeof(myObjType).Assembly;
string TheRightPath=ca.Location;

Then my ASPX page uses the component to call some of its methods, and i
get the following error in my browser (i traduced the messages, i get
them in french):

Server in error in application '/MyWebApplication'. --------------------
Impossible to find file
"c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net
files\MyWebApplication\c4e535bc\84b07167\assembly\dl2\5801a542\022a2a6f_
f79fc401\MyXmlFile.xml".

I think IIS creates an "execution folder", where the loading of the XML
doesn't work anymore, because the executed DLL is not in the same folder
as the xml...

Thanks for your help...
 
G

Girish Bharadwaj

You should not use the location. You need to use the PhysicalPath, or
ApplicationPath or some such thing that exists server side on to get the
path ( Or you can use Server.MapPath(null) to get the current application
directory).

The location of the assembly will be some cache directory (to support shadow
copy implementation) as you found out.
 
G

Girish bharadwaj

I think This would be wrong because the location is already the physical
path but to the cache folder maintained by ASP.NET.
 
P

Plon Plon

Yes, that's what i found. Getting the location retrieves me the cache
path (the path "c:\winnt\microsoft.net\framework\v1.1.4322\temporary
asp.net
files\MyWebApplication\c4e535bc\84b07167\assembly\dl2")

What i want to retrieve is the path where the "original" copy of the dll
is... Because my XML file is in this folder, not in the cache folder...

As Girish said in his first post, i'll try the PhysicalPath, or
ApplicationPath or Server.MapPath(null).

I'll post my results. Thanks for your help.
 
P

Plon Plon

Ok, it seems that the applicationPath and the PhysicalPath are some
"request" properties, so it works fine to retrieve them in my ASPX page.

But I can't use these ones because the loading of the XML file is done
in the DLL. It's the DLL that must calculate the XML path, because this
DLL can both be used by the ASP.NET site and a c/s application (and
strangely i don't have problems when i use the DLL with my c/s
application)...

Has someone another idea?
 
G

Girish Bharadwaj

I believe you should be able to reference
HttpContext.Current.Request.PhysicalPath from your assembly as well. Of
course,you need to use this conditionally to see if HttpContext.Current is
null or not.
 

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

Top