Kenny's Two Pennies

...and that's just about what it's worth
  Home |  Contact |   |  Login

Thursday, June 25, 2009

.Net COM object and app.config continued...

Well, I found that my previous post doesn't really work. I spent more time and learned the following:

  • I can't easily change the location of the app.config file. The way to do it involves setting up a new AppDomain.
  • The app.config file lives in the directory with the base executable. In the case of a COM object called from within a classic ASP page, this is the directory where w3wp.exe resides. On my computer (running 64-bit Vista), the directory is at C:\Windows\SysWOW64\inetsrv. So I created a w3wp.exe.config in that directory and voila!

That solves the problem of the config file.

My next issue was that I had to call code that wanted to get other file information from the operating directory.

By "operating directory", the code I was calling was using AppDomain.CurrentDomain.BaseDirectory

This gave me a problem, because when running under IIS, I didn't have permissions to scan a directory in c:\Windows. I couldn't even give permissions to the directory, I got an error dialog.

My solution was to change the "operating directory" to the location of the COM dll. To do this, I used the following:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", string.Empty)

Since I had directory scanning rights on that directory, it worked -- I can now call a COM object that in turn uses nHibernate to read data from a database.

Whew! 

posted @ Thursday, June 25, 2009 12:25 AM | Feedback (0) |