problem implimenting version 2.0 domain objects in MVC
Hi,
I have a problem utilising my beerhouse version 2.0 domain objects in thebeerhouse MVC project.
Instead of using the mvc's books LINQ to SQL schema, i wish to use the same DAL, BLL principles found in the .net 2.0 book, but apply an MVC UI.
I get the following error message -
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: An error occurred creating the configuration section handler for theNewham: Could not load file or assembly 'TheNewham' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 23: </sectionGroup>
Line 24: </sectionGroup>
Line 25: <section name="theNewham" type="NewhamCoalition.Configuration.TheNewhamSecti on, TheNewham" />
Line 26: </configSections>
For clarity, I've also included the following code from my project -
In my web.config file I have the following section and subsection -
<theNewham>
<news providerType="NewhamCoalition.DAL.SqlClient.SqlNew sProvider" pageSize="10" enableCaching="true" cacheDuration="300" />
In my Configuration folder I have a class called TheNewhamSection.cs -
namespace NewhamCoalition.Configuration
{
public class TheNewhamSection : ConfigurationSection
{
public readonly static TheNewhamSection current = (TheNewhamSection)WebConfigurationManager.GetSecti on("theNewham");
[ConfigurationProperty("defaultConnectionStringName ", DefaultValue = "LocalSqlServer")]
public string DefaultConnectionStringName
{
get { return (string)base["defaultConnectionStringName"]; }
set { base["connectionStdefaultConnectionStringNameringNa me"] = value; }
}
[ConfigurationProperty("defaultCacheDuration", DefaultValue = "600")]
public int DefaultCacheDuration
{
get { return (int)base["defaultCacheDuration"]; }
set { base["defaultCacheDuration"] = value; }
}
[ConfigurationProperty("news", IsRequired = true)]
public NewsElement News
{
get { return (NewsElement)base["news"]; }
}
}
}
I also have a NewsElement class -
namespace NewhamCoalition.Configuration
{
public class NewsElement : ConfigurationElement
{
[ConfigurationProperty("connectionStringName")]
public string ConnectionStringName
{
get { return (string)base["connectionStringName"]; }
set { base["connectionStringName"] = value; }
}
public string ConnectionString
{
get
{
string connStringName = (string.IsNullOrEmpty(this.ConnectionStringName) ?
Configuration.TheNewhamSection.current.DefaultConn ectionStringName : this.ConnectionStringName);
return WebConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
}
}
[ConfigurationProperty("providerType", DefaultValue = "NewhamCoalition.Models.DAL.SqlClient.SqlNewsProvi der")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
[ConfigurationProperty("pageSize", DefaultValue = "10")]
public int PageSize
{
get { return (int)base["pageSize"]; }
set { base["pageSize"] = value; }
}
[ConfigurationProperty("enableCaching", DefaultValue = "true")]
public bool EnableCaching
{
get { return (bool)base["enableCaching"]; }
set { base["enableCaching"] = value; }
}
[ConfigurationProperty("cacheDuration")]
public int CacheDuration
{
get
{
int duration = (int)base["cacheDuration"];
return (duration > 0 ? duration : Configuration.TheNewhamSection.current.DefaultCach eDuration);
}
set { base["cacheDuration"] = value; }
}
}
}
Upon setting breakpoints, I notice that when stepping through the code in my DAL.NewsProvider, the NewsProvider instance is assigned a null value -
if (_instance == null)
_instance = (NewsProvider)Activator.CreateInstance(
Type.GetType(Configuration.TheNewhamSection.curren t.News.ProviderType));
I think the problem here relates to the section name settings in my web.config. The concrete sql provider isn't reached. Is this because in my .asp .net 2 project the provider was placed in my App_code folder and therefore automatically compiled? If this is the case can anyone please point me in the right direction? Would I need to use class libraries? Again, if so, any links to tutorials would be appreciated.
Thanks.
Last edited by teabag99; December 11th, 2010 at 10:21 AM..
|