views:

155

answers:

3

Ok i created a .net assembly and it works fine from my asp.net website. I now want to host it as COM, so i can use it on an old legacy asp website. It kinda works, except it won't read the appsettings from the configuration file.

I would think it should read it from the same folder where i registered my assembly with regasm and where the .dll resides. I tried copying the config file to two extra files (in case it read from a different named file besides "assembly-file-name"+.config The two files are app.config and application.config - it doesn't seem to read from any of them.

Where does my .net assembly read its configuration from when hosted as COM?

A: 

Sombody correct me if I'm wrong, but I don't think a DLL reads a config file at all. Even though you technically can create a config file for DLL projects as well (using the project properties), I don't think you're supposed to configure a DLL like that and I don't think the framework supports that.

There are two ways now:

  1. Have the caller pass respective settings values to the objects as parameters
  2. Build a method that reads the settings itself and call the method after creating the object.

EDIT
To check, you should name the config file application-name.config.xml, like for a WebForms application. But as I said, I doubt that it'll work...

Thorsten Dittmar
Dog nammit, I hope you're wrong ;)
Per Hornshøj-Schierbeck
I know the following: When creating .NET DLLs that contain typed data sets, the connection strings will be stored in the DLLs app.config. You can then copy them from the DLLs app.config into the application's app.config and they will be used, as long as you also copy the namespace information, etc. But that won't work for a legacy ASP application I guess...
Thorsten Dittmar
The Framework supports it. At runtime the DLL searches for its configuration on the EXEs config file.
Alfred Myers
A: 

Ok i found a solution that makes me happy.

I ended up hosting the COM object in Component Services. On the package i picked Properties and selected the Activation tab, there i entered the location of my config file in "Application Root Directory". Now to make it work, i had to rename my config file to application.config and somehow i also had to create a new file in the same location called application.manifest with the following data:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>

This actually solves the problem of having "the dll" read the config file - actually since component services is the host (in place of the exe/website) it determines the location/config.

Woop - and thanks for the input guys - i hadn't thought of the problem Thorsten mentioned before.

Per Hornshøj-Schierbeck
+1  A: 

If by COM you mean a COM application, then you should put your configuration in a file named after the EXE. YourApp.Exe -> YourApp.exe.config

If by COM you mean COM+, then take a look at http://blogs.msdn.com/heikkiri/archive/2005/11/10/491568.aspx

Alfred Myers
I think you need credit for this - i found it somewhere, it might as well have been your site - anyways it explains it perfectly :)
Per Hornshøj-Schierbeck