J
Jeff Hegedus
I have a dll that requires some configuration data. I put the configuration
data in a custom configuration section in a config file that is loaded in
the installation folder of the dll. If I install the dll to the same
directory as the exe which uses it, everything works as expected but if I
load the dll in any other directory, I get the following error...
2007-02-04 16:36:51,171 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
dllPath =
C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\bin\Debug\CentrifugeBHO.dll
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
Assembly.GetExecutingAssembly().FullName = CentrifugeBHO, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=558ea11974e40b85
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
Exception1
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] - An
error occurred creating the configuration section handler for dllConfig:
Could not load file or assembly 'CentrifugeBHO, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=558ea11974e40b85' or one of its
dependencies. The system cannot find the file specified.
(C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\bin\Debug\CentrifugeBHO.dll.config
line 6)
2007-02-04 16:36:51,218 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
at
System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String
configKey, Boolean& isRootDeclaredHere)
at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean
getRuntimeObject, Boolean requestIsHere, Object& result, Object&
resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String
configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.ConfigurationSectionCollection.Get(String name)
at System.Configuration.ConfigurationSectionCollection.get_Item(String
name)
at CentrifugeBHO.CentrifugeBHO.OnDocumentComplete(Object frame, Object&
urlObj) in
C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\CentrifugeBHO.cs:line
268
Here is the config file...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection, CentrifugeBHO,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
</configSections>
<dllConfig fileName="default.txt" maxIdleTime="01:30:30" permission="Read"
/>
</configuration>
The following line is where the error is occuring...
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection, CentrifugeBHO,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
I have also tried using a full path as below instead of just an assembly
name with the same results...
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection,
file:///C:/Projects/VSS/Centrifuge/InformationCentrifuge/CentrifugeBHO/bin/Debug/CentrifugeBHO.dll,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
Here is the code that loads the configuration in the dll...
log.Debug("dllPath = " + dllPath);
System.Configuration.Configuration config = null;
// Get the application configuration file.
try
{
config =
System.Configuration
.ConfigurationManager
.OpenExeConfiguration(dllPath);
//.OpenExeConfiguration("C:\\Documents and
Settings\\jhegedus\\My
Documents\\projects\\C#\\InformationCentrifuge\\CentrifugeBHO\\bin\\Debug\\CentrifugeBHO.dll");
}
catch (Exception e)
{
log.Debug(e.Message);
log.Debug(e.StackTrace);
throw (e);
}
// If the section does not exist in the configuration
// file, create it and save it to the file.
String customSectionName = "dllConfig";
try
{
log.Debug("Assembly.GetExecutingAssembly().FullName = " +
Assembly.GetExecutingAssembly().FullName);
if (config.Sections[customSectionName] == null)
{
log.Debug("config.Sections[customSectionName] == null");
//uugh();
CentrifugeConfigurationSection custSection = new
CentrifugeConfigurationSection();
config.Sections.Add(customSectionName, custSection);
custSection =
(CentrifugeConfigurationSection)config.GetSection(customSectionName);
custSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
catch (Exception e)
{
log.Debug("Exception1");
log.Debug(e.Message);
log.Debug(e.StackTrace);
throw (e);
}
Do you have any suggestions to resolve the problem?
Thanks in advance,
Jeff
data in a custom configuration section in a config file that is loaded in
the installation folder of the dll. If I install the dll to the same
directory as the exe which uses it, everything works as expected but if I
load the dll in any other directory, I get the following error...
2007-02-04 16:36:51,171 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
dllPath =
C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\bin\Debug\CentrifugeBHO.dll
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
Assembly.GetExecutingAssembly().FullName = CentrifugeBHO, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=558ea11974e40b85
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
Exception1
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] - An
error occurred creating the configuration section handler for dllConfig:
Could not load file or assembly 'CentrifugeBHO, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=558ea11974e40b85' or one of its
dependencies. The system cannot find the file specified.
(C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\bin\Debug\CentrifugeBHO.dll.config
line 6)
2007-02-04 16:36:51,218 [1] DEBUG CentrifugeBHO.CentrifugeBHO [(null)] -
at
System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String
configKey, Boolean& isRootDeclaredHere)
at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean
getRuntimeObject, Boolean requestIsHere, Object& result, Object&
resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String
configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.ConfigurationSectionCollection.Get(String name)
at System.Configuration.ConfigurationSectionCollection.get_Item(String
name)
at CentrifugeBHO.CentrifugeBHO.OnDocumentComplete(Object frame, Object&
urlObj) in
C:\Projects\VSS\Centrifuge\InformationCentrifuge\CentrifugeBHO\CentrifugeBHO.cs:line
268
Here is the config file...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection, CentrifugeBHO,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
</configSections>
<dllConfig fileName="default.txt" maxIdleTime="01:30:30" permission="Read"
/>
</configuration>
The following line is where the error is occuring...
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection, CentrifugeBHO,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
I have also tried using a full path as below instead of just an assembly
name with the same results...
<section name="dllConfig"
type="CentrifugeBHO.CentrifugeConfigurationSection,
file:///C:/Projects/VSS/Centrifuge/InformationCentrifuge/CentrifugeBHO/bin/Debug/CentrifugeBHO.dll,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=558ea11974e40b85"
allowLocation="true" allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="true" />
Here is the code that loads the configuration in the dll...
log.Debug("dllPath = " + dllPath);
System.Configuration.Configuration config = null;
// Get the application configuration file.
try
{
config =
System.Configuration
.ConfigurationManager
.OpenExeConfiguration(dllPath);
//.OpenExeConfiguration("C:\\Documents and
Settings\\jhegedus\\My
Documents\\projects\\C#\\InformationCentrifuge\\CentrifugeBHO\\bin\\Debug\\CentrifugeBHO.dll");
}
catch (Exception e)
{
log.Debug(e.Message);
log.Debug(e.StackTrace);
throw (e);
}
// If the section does not exist in the configuration
// file, create it and save it to the file.
String customSectionName = "dllConfig";
try
{
log.Debug("Assembly.GetExecutingAssembly().FullName = " +
Assembly.GetExecutingAssembly().FullName);
if (config.Sections[customSectionName] == null)
{
log.Debug("config.Sections[customSectionName] == null");
//uugh();
CentrifugeConfigurationSection custSection = new
CentrifugeConfigurationSection();
config.Sections.Add(customSectionName, custSection);
custSection =
(CentrifugeConfigurationSection)config.GetSection(customSectionName);
custSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
catch (Exception e)
{
log.Debug("Exception1");
log.Debug(e.Message);
log.Debug(e.StackTrace);
throw (e);
}
Do you have any suggestions to resolve the problem?
Thanks in advance,
Jeff