I am stuck! this seems really daft but I can not see where I am going wrong. I am creating a 2.0 C# ASP.NET website. I am trying to use a custom section in the web.config file with:
DatabaseFactorySectionHandler sectionHandler = ConfigurationManager.GetSection("DatabaseFactoryConfiguration") as DatabaseFactorySectionHandler;
I have a separate DLL for the Objects which are in Bailey.DataLayer namespace. But when I run the test.aspx page I get the following error:
System.Configuration.ConfigurationErrorsException was unhandled by user code
Message="An error occurred creating the configuration section handler for DatabaseFactoryConfiguration: Could not load file or assembly 'Bailey.DataLayer' or one of its dependencies. The system cannot find the file specified. (C:\\Documents and Settings\\Administrator.PIP\\My Documents\\Visual Studio 2005\\WebSites\\bailey\\web.config line 13)"
Source="System.Configuration"
The class that I am trying to get is as follows:
namespace Bailey.DataLayer
{
public sealed class DatabaseFactorySectionHandler : ConfigurationSection
{
[ConfigurationProperty("Name")]
public string Name
{
get { return (string)base["Name"]; }
}
[ConfigurationProperty("ConnectionStringName")]
public string ConnectionStringName
{
get { return (string)base["ConnectionStringName"]; }
}
public string ConnectionString
{
get
{
try
{
return ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
}
catch (Exception excep)
{
throw new Exception("Connection string " + ConnectionStringName +
" was not found in web.config. " +
excep.Message);
}
}
}
}
}
The web config file has this section:
<configSections>
<section name="DatabaseFactoryConfiguration"
type="Bailey.DataLayer.DatabaseFactorySectionHandler, Bailey.DataLayer" />
</configSections>
I have done this in a console app without a problem but can not see any differences apart from it being in a web page.
EDIT
It all compiles and throws the error at runtime so I can only assume it find the assembly because it is referenced in the test.aspx.cs page.
I have the following using statement at the top of the test.aspx.cs page:
using Bailey.DataLayer;
Here is the whole web.config file so there is no confusion:
<configuration>
<configSections>
<section name="DatabaseFactoryConfiguration" type="Bailey.DataLayer.DatabaseFactorySectionHandler, Bailey.DataLayer" />
</configSections>
<appSettings/>
<connectionStrings>
<add name="BaileyMDFConString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bailey.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<DatabaseFactoryConfiguration Name="System.Data.SqlClient" ConnectionStringName="BaileyMDFConString" />
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
Originally Answered: What is the full form of C ? C - Compiler . C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.
Either you're using the wrong name (i.e. it's not called Bailey.DataLayer.dll), or it's not being copied to the bin directory on build. This last one doesn't seem likely however.
(See my comments on the question for clarification).
Ok ... I had the same issue. None of the above solutions helped. In my case my config file was in the same dll as that of web.config. I simply removed the namespace from the config section and that fixed my issue.
Not working
<configSections>
<section name="authorizedServerSection" type="ProjectName.ClientApi.Filters.AuthorizedServerSection, ProjectName.ClientApi.Filters" requirePermission="false"/>
Working
<configSections>
<section name="authorizedServerSection" type="ProjectName.ClientApi.Filters.AuthorizedServerSection" requirePermission="false"/>
As soon as I removed the namespace , ProjectName.ClientApi.Filters
it started working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With