473,725 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Configuration - dll

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.C entrifugeBHO [(null)] -
dllPath =
C:\Projects\VSS \Centrifuge\Inf ormationCentrif uge\CentrifugeB HO\bin\Debug\Ce ntrifugeBHO.dll
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.C entrifugeBHO [(null)] -
Assembly.GetExe cutingAssembly( ).FullName = CentrifugeBHO, Version=1.0.0.0 ,
Culture=neutral , PublicKeyToken= 558ea11974e40b8 5
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.C entrifugeBHO [(null)] -
Exception1
2007-02-04 16:36:51,202 [1] DEBUG CentrifugeBHO.C entrifugeBHO [(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= 558ea11974e40b8 5' or one of its
dependencies. The system cannot find the file specified.
(C:\Projects\VS S\Centrifuge\In formationCentri fuge\Centrifuge BHO\bin\Debug\C entrifugeBHO.dl l.config
line 6)
2007-02-04 16:36:51,218 [1] DEBUG CentrifugeBHO.C entrifugeBHO [(null)] -
at
System.Configur ation.BaseConfi gurationRecord. FindAndEnsureFa ctoryRecord(Str ing
configKey, Boolean& isRootDeclaredH ere)
at
System.Configur ation.BaseConfi gurationRecord. GetSectionRecur sive(String
configKey, Boolean getLkg, Boolean checkPermission , Boolean
getRuntimeObjec t, Boolean requestIsHere, Object& result, Object&
resultRuntimeOb ject)
at System.Configur ation.BaseConfi gurationRecord. GetSection(Stri ng
configKey, Boolean getLkg, Boolean checkPermission )
at System.Configur ation.Configura tionSectionColl ection.Get(Stri ng name)
at System.Configur ation.Configura tionSectionColl ection.get_Item (String
name)
at CentrifugeBHO.C entrifugeBHO.On DocumentComplet e(Object frame, Object&
urlObj) in
C:\Projects\VSS \Centrifuge\Inf ormationCentrif uge\CentrifugeB HO\CentrifugeBH O.cs:line
268

Here is the config file...

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="dllConfig "
type="Centrifug eBHO.Centrifuge ConfigurationSe ction, CentrifugeBHO,
Version=1.0.0.0 , Culture=neutral , PublicKeyToken= 558ea11974e40b8 5"
allowLocation=" true" allowDefinition ="Everywhere "
allowExeDefinit ion="MachineToA pplication" restartOnExtern alChanges="true "
requirePermissi on="true" />
</configSections>
<dllConfig fileName="defau lt.txt" maxIdleTime="01 :30:30" permission="Rea d"
/>
</configuration>

The following line is where the error is occuring...

<section name="dllConfig "
type="Centrifug eBHO.Centrifuge ConfigurationSe ction, CentrifugeBHO,
Version=1.0.0.0 , Culture=neutral , PublicKeyToken= 558ea11974e40b8 5"
allowLocation=" true" allowDefinition ="Everywhere "
allowExeDefinit ion="MachineToA pplication" restartOnExtern alChanges="true "
requirePermissi on="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="Centrifug eBHO.Centrifuge ConfigurationSe ction,
file:///C:/Projects/VSS/Centrifuge/InformationCent rifuge/CentrifugeBHO/bin/Debug/CentrifugeBHO.d ll,
Version=1.0.0.0 , Culture=neutral , PublicKeyToken= 558ea11974e40b8 5"
allowLocation=" true" allowDefinition ="Everywhere "
allowExeDefinit ion="MachineToA pplication" restartOnExtern alChanges="true "
requirePermissi on="true" />

Here is the code that loads the configuration in the dll...

log.Debug("dllP ath = " + dllPath);
System.Configur ation.Configura tion config = null;

// Get the application configuration file.
try
{
config =
System.Configur ation
.ConfigurationM anager
.OpenExeConfigu ration(dllPath) ;
//.OpenExeConfigu ration("C:\\Doc uments and
Settings\\jhege dus\\My
Documents\\proj ects\\C#\\Infor mationCentrifug e\\CentrifugeBH O\\bin\\Debug\\ CentrifugeBHO.d ll");
}
catch (Exception e)
{
log.Debug(e.Mes sage);
log.Debug(e.Sta ckTrace);
throw (e);
}

// If the section does not exist in the configuration
// file, create it and save it to the file.
String customSectionNa me = "dllConfig" ;

try
{
log.Debug("Asse mbly.GetExecuti ngAssembly().Fu llName = " +
Assembly.GetExe cutingAssembly( ).FullName);
if (config.Section s[customSectionNa me] == null)
{
log.Debug("conf ig.Sections[customSectionNa me] == null");
//uugh();
CentrifugeConfi gurationSection custSection = new
CentrifugeConfi gurationSection ();
config.Sections .Add(customSect ionName, custSection);
custSection =
(CentrifugeConf igurationSectio n)config.GetSec tion(customSect ionName);
custSection.Sec tionInformation .ForceSave = true;
config.Save(Con figurationSaveM ode.Full);
}
}
catch (Exception e)
{
log.Debug("Exce ption1");
log.Debug(e.Mes sage);
log.Debug(e.Sta ckTrace);
throw (e);
}

Do you have any suggestions to resolve the problem?

Thanks in advance,

Jeff
Feb 6 '07 #1
6 4809
Hello Jeff,

From your description, you're getting "could not find file or assembly ..."
error when try launch an .net application which read some custom
configuration sectino data from app.config file, correct?

As the error message indicate, the problem here is that the .net runtime
can not correctly find the assembly for your custom configuration section.
And based on my previous description, I think the cause here is that you
did not put the custom configuration section assembly in the .NET runtime's
expected searching path. For .net framework application, its runtime
host(CLR runtime) has a regular rule of how to search for dependency
assemblies. Generally, when an .net application need to locate a certain
assembly it references, it will go through the following steps:

**if the referenced assembly is strong-named, lookup the GAC first

**if GAC not exists, look into Application configureation file(App.config )
to see whether there is codebase setting indicate a specfiic location of
the assembly(on file system or over internet)

**Perform local assembly probing under the application's root folder(you
can configure which sub folders to probing in app.config file).

Here is the MSDN refernce that detailedly describe this:

#How the Runtime Locates Assemblies
http://msdn2.microsoft.com/en-us/library/yx7xezcf.aspx

For your scenario, I think you can consider the following options to deploy
the assembly of your custom configuration section:

1. strong-named your assembly and put it into machine's GAC so that any
..net application running on that machine can locate it(if it has referenced
your assembly).

2. Use <codebasesettin g to specify a particular location(such as file
system path or http web url) for your assembly, you can put the <codebase>
setting in the certain application(whi ch want to reference that custom
assembly)'s app.config file. For syntax setting, you can refer to the
following document:

#Specifying an Assembly's Location
http://msdn2.microsoft.com/en-us/library/4191fzwb.aspx

#<codeBaseEleme nt
http://msdn2.microsoft.com/en-us/library/efs781xb.aspx

BTW, you should not put file path in the "type" attribute of the <section
element(only assembly name is necessary), searching path is determined by
the .NET's CLR searching rules as described above.
3. Put the assembly in same directory with the .net application(exe ) which
reference that certain assembly.

Hope this helps. If you have anything unclear or any further questions on
this, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.



Feb 6 '07 #2
Steven,

Thanks for the reply. I have been able to make option#3 work but it is not
my first choice as I am not sure where the exe might be that uses the
assembly. I have examined the article on how the runtime locates assemblies
and tried both installing in the GAC and using the <codeBaseelemen t. I
had not had any luck as of yet which is why I posted to the group. I'll
continue trying now that I have confirmation that I am on the right track.
I'll post back to the group once I have resolved or if I continue to have
difficulties.

Thanks,

Jeff
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:Iw******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hello Jeff,

From your description, you're getting "could not find file or assembly
..."
error when try launch an .net application which read some custom
configuration sectino data from app.config file, correct?

As the error message indicate, the problem here is that the .net runtime
can not correctly find the assembly for your custom configuration section.
And based on my previous description, I think the cause here is that you
did not put the custom configuration section assembly in the .NET
runtime's
expected searching path. For .net framework application, its runtime
host(CLR runtime) has a regular rule of how to search for dependency
assemblies. Generally, when an .net application need to locate a certain
assembly it references, it will go through the following steps:

**if the referenced assembly is strong-named, lookup the GAC first

**if GAC not exists, look into Application configureation file(App.config )
to see whether there is codebase setting indicate a specfiic location of
the assembly(on file system or over internet)

**Perform local assembly probing under the application's root folder(you
can configure which sub folders to probing in app.config file).

Here is the MSDN refernce that detailedly describe this:

#How the Runtime Locates Assemblies
http://msdn2.microsoft.com/en-us/library/yx7xezcf.aspx

For your scenario, I think you can consider the following options to
deploy
the assembly of your custom configuration section:

1. strong-named your assembly and put it into machine's GAC so that any
net application running on that machine can locate it(if it has referenced
your assembly).

2. Use <codebasesettin g to specify a particular location(such as file
system path or http web url) for your assembly, you can put the <codebase>
setting in the certain application(whi ch want to reference that custom
assembly)'s app.config file. For syntax setting, you can refer to the
following document:

#Specifying an Assembly's Location
http://msdn2.microsoft.com/en-us/library/4191fzwb.aspx

#<codeBaseEleme nt
http://msdn2.microsoft.com/en-us/library/efs781xb.aspx

BTW, you should not put file path in the "type" attribute of the <section
>element(only assembly name is necessary), searching path is determined by
the .NET's CLR searching rules as described above.
3. Put the assembly in same directory with the .net application(exe ) which
reference that certain assembly.

Hope this helps. If you have anything unclear or any further questions on
this, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.



Feb 8 '07 #3
Thanks for your reply Jeff,

As for the following things you mentioned:

=============== ==
I have examined the article on how the runtime locates assemblies
and tried both installing in the GAC and using the <codeBaseelemen t. I
had not had any luck as of yet which is why I posted to the group.
===============

If you put the assembly into GAC, then you no longer need to use <codebase>
or copy it to the same directory as the exe and any application on the
machine that reference it can locate it from GAC. However, you need to
first strong-name that assembly(only strong-named asssembly can be
installed into GAC). Here are some knowledge base articles demonstrate on
creating strong-name assembly and deply them in GAC:
#Creating and Using Strong-Named Assemblies
http://msdn2.microsoft.com/en-us/library/xwb8f617.aspx

#How to install an assembly in the Global Assembly Cache in Visual Basic
..NET or in Visual Basic 20
http://support.microsoft.com/kb/315682/en-us

#How to consume assemblies that are located in a folder that is different
from the application base folder in Visual Basic .NET or in Visual Basic
2005
http://support.microsoft.com/kb/897297/en-us
If you need any further help on this, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 8 '07 #4
Steven,

I have tried all options and none seems to work with the exception of
installing the assembly in the same folder as the exe which is not my
preferred option. The exe in this case is InternetExplore r and the dll is a
browser helper object. The dll has a configuration file that has a custom
configuration section in it. The dll itself is found correctly for any of
the three scenarios, but the only scenario in which the custom config
section is successfully loaded is when the dll is is installed in the same
folder as the exe.

The exe is not a .NET assembly and so it does not have a config file I can
use to set up assembly loading. It is calling my dll through COM Interop.
It does not appear that the information in the config file I load with the
dll is used by the .NET loading process. I don't understand why it doesn't
work when the dll is loaded into the GAC though.

I have a few more ideas I want to try and will let you know if they are
successful. If you have any other ideas that might help, I would appreciate
them.

Thanks,

Jeff
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:LX******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Thanks for your reply Jeff,

As for the following things you mentioned:

=============== ==
I have examined the article on how the runtime locates assemblies
and tried both installing in the GAC and using the <codeBaseelemen t. I
had not had any luck as of yet which is why I posted to the group.
===============

If you put the assembly into GAC, then you no longer need to use
<codebase>
or copy it to the same directory as the exe and any application on the
machine that reference it can locate it from GAC. However, you need to
first strong-name that assembly(only strong-named asssembly can be
installed into GAC). Here are some knowledge base articles demonstrate on
creating strong-name assembly and deply them in GAC:
#Creating and Using Strong-Named Assemblies
http://msdn2.microsoft.com/en-us/library/xwb8f617.aspx

#How to install an assembly in the Global Assembly Cache in Visual Basic
NET or in Visual Basic 20
http://support.microsoft.com/kb/315682/en-us

#How to consume assemblies that are located in a folder that is different
from the application base folder in Visual Basic .NET or in Visual Basic
2005
http://support.microsoft.com/kb/897297/en-us
If you need any further help on this, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.


Feb 9 '07 #5
Thanks for your reply Jeff,

As you mentioned that the exe is IE and the dll is a BHO assembly, this is
very important since IE is not a managed application. Also, as for the
configuration file, are you putting it in the same directory with
IE(iexplore.exe ) and rename it as iexplore.exe.co nfig? This is necessary
because .net assembly doesn't have runtime config file, only exe can have a
config file to manage the .net runtime settings.

Also, i'm bit surprised that installing assembly into GAC doesn't work.

for managed BHO dev and deploy, you can refer to this article:

#Building Browser Helper Objects using Managed Code
http://simonguest.com/blogs/smguest/...g-Browser-Help
er-Objects-using-Managed-Code.aspx

In addition, I suggest you try using the fuslogvw.exe utility to trace the
assembly binding failure, this is a very useful tool on troubleshooting
.net CLR assembly loading issue:

#Assembly Binding Log Viewer (Fuslogvw.exe)
http://msdn2.microsoft.com/en-us/lib...c4(VS.80).aspx

Please feel free to let me know your result.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #6
Hello Jeff,

How are you doing on this issue, have you got any further progress? If
there is anything else we can help, please feel free to followup there.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2278
by: rdcpro | last post by:
In reading MSDN docs on creating custom Configuration sections, I found this page: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfcustomelementfornamevaluesectionhandlerdictionarysectionhandler.asp At the very bottom, it says: Configuration File This element can be used in the application configuration file, machine configuration file (Machine.config), and Web.config files that are not at the
3
1594
by: Laser Lu | last post by:
Hello, everybody, In order to avoid making web.config lengthy, I just moved some custom configuration settings out from web.config, and centralized them into an xml file, which names data.config. It works fine except for one thing that the custom configuration file has a poor change awareness. Custom configuration settings can not be refreshed after the data.config file was modified. I wish the custom data.config file can works like the...
3
5620
by: Jason Richmeier | last post by:
Is it possible to create a custom configuration file (other than app.config) that can be processed by classes in the System.Configuration namespace? I have seen a ton of articles that talk about custom sections (inside the app.config file) but I would like to make an entirely new config file. I opened a custom config file with the ConfigurationManager class but it seemd as if it ignored all of the content in the config file. Is there...
7
10828
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in code. The configuration section is contained within the exe (it's a simple test case!) and everything works well debugging within the IDE or if the application is deployed on a drive or share that has been granted full trust. For the share the...
0
1622
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root level web.config and an application level web.config, with the application web.config inheriting from the root level web.config. I am receiving the following message when compiling the web application... "....Section or group name...
4
2697
balabaster
by: balabaster | last post by:
Okay, I decided that I needed to understand the whole custom configuration file bits and so I've spent some time playing around with it. It seems (in the most) relatively straight forward. However, I've come unstuck with one scenario that I'm trying to figure out the code for: Consider the following configuration: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="DummySection"...
1
1630
by: =?Utf-8?B?SmFzb24gUmljaG1laWVy?= | last post by:
This may have been addressed in another post but I was unable to find what I was looking for. I am trying to create a custom configuration section that is element-centric instead of attribute-centric (mostly out of preference). For example... <Date> <Year>2008</Year>
4
1662
by: David Williams | last post by:
I am familiar with creating custom configuration settings and accessing them. However, for a current requirement, I need to control the various settings in my custom configuration section by virtual location of the pages accessing the configuration information. The best way that I know is to do this via the use of the location tag in the web.config. However, I can not seem to get the correct instance of the configuration section in my...
2
3782
by: shapper | last post by:
Hello, On a custom Web.Config section I keep having the same error. This is driving me crazy!!! I keep having the following error: Unrecognized attribute 'Type'. Note that attribute names are case- sensitive. (C:\Documents and Settings\Miguel\My Documents\Website \web.config line 42)
0
8886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3217
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2154
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.