Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950
This is the forum to discuss the Wrox book ASP.NET MVC Website Programming Problem Design Solution by Nicholas Berardi, Al Katawazi, and Marco Bellinaso; ISBN: 9780470410950
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 10th, 2010, 09:31 PM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 09:21 AM.
Reply With Quote
  #2 (permalink)  
Old December 11th, 2010, 09:24 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default changed code to no avail

First thing - I tried three times to edit the post so that unwanted spaces dont appear in the code, but the forum tools wont update, so please ignore any unexpected breaks in the code!

I've just tried a couple of code changes but to no avail -

First, I moved the DAL code and ConfigSection.cs and Globals.cs to a sperate class Library called NewhamLibrary. Compiled the class Libary and added a reference to this from a new project. No change (therefore this rules out my earlier theory that there may be a problem using an MVC project without the feature of an App_code directory.

I think this is a problem with the web.config section and subsections not being correctely configured. I altered the name section to - <section name="theNewham" type="NewhamLibrary.TheNewhamSection" /> from <section name="theNewham" type="NewhamLibrary.TheNewhamSection", TheNewham />. I now get a different error message -

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: type

Source Error:

Line 13: {
Line 14: if (_instance == null)
Line 15: _instance = (NewsProvider)Activator.CreateInstance(
Line 16: Type.GetType(Globals.Settings.News.ProviderType));
Line 17: return _instance;


I have now been working on this for over four days!!

Please help - the annoying thing is that this runs fine in the .net 2 version, and since .net mvc uses the sane framework, there should not be a problem!
Reply With Quote
  #3 (permalink)  
Old January 22nd, 2011, 06:49 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem solved

Sorry - I completely forgot about this post!
I eventually sorted out the problem after working with WebConfigurationManager.GetSection method to pull the info from web.config.
After wiring this up it began to dawn on me that I would have to scrap the idea of using my existing domain models in conjunction with linq to sql. The use of link to sql in thebeerhouse project, is to act within the 'Model', and as such should be viewed as part of the data domain layer.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors while upgrade theBeerHouse mvc project form asp.net mvc 1.0 to 2.0 vanbach1304 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 April 20th, 2010 06:43 AM
TheBeerHouse MVC preview ASP.NET MVC Website Programming Problem Design Solution jminatel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 July 18th, 2009 09:16 AM
preview version of TheBeerHouse MVC on CodePlex vantoko BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 68 June 1st, 2009 09:55 AM
Problem in upload photo to domain server krishnamoorthymca Linux 0 April 4th, 2007 03:48 AM
Same pages for sub domain from main domain vivek_inos ASP.NET 1.0 and 1.1 Professional 1 February 13th, 2007 09:15 AM



All times are GMT -4. The time now is 03:41 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.