Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2010, 02:01 PM
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with SiteProvider

I'm trying to implement ONLY the store portion of the Beer House WITHOUT any personalization, etc., Nor am I using memership since this will run on an internal intranet.

The problem I'm having is in the SiteProvider Class which only has the Store() property defined.

I receive the following for Return StoreProvider.Instance:

{value cannot be null:parameter name:Type}

The values of the storeElement from the web.config are created by not available here.

Can anyone provide suggestions on how to set the StoreProvider.Instance in this situation?
 
Old February 16th, 2010, 03:25 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

It appears you are passing null to Activator.CreateInstance. The CreateInstance method requires the type of Globals.Settings.Store.ProviderType in order to create the instance.

It gets that type from the web.config, via the Settings property of the Globals class, which is being abstracted by the classes in the ConfigSection.cs file.

So, the question is - have you pulled in all of that functionality?

You will need to do that for this to work. Otherwise, if you don't require the ability to swap put providers, you could just hard-code the provider into the CreateInstance method.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 16th, 2010, 03:35 PM
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee:

thanks for the quick response.

I have implemented all of the properties in the ConfigSection.vb and the Web.Config.

When stepping through the contents of the Globals.settings I can see all of the properties. It only becomes null when I hit the SiteProvider class. Here is the complete code of the SiteProvider class:

Imports Microsoft.VisualBasic
Namespace JG.BMTStore.DAL
Public NotInheritable Class SiteProvider
Public Shared ReadOnly Property Store() As StoreProvider
Get
Return StoreProvider.Instance
End Get

End Property
End Class
End Namespace

I've changed the namespace throughout the application.
 
Old February 16th, 2010, 04:02 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

What I'm saying here is that the value that is returned as StoreProvider.Instance is derived from the Instance property in StoreProvider.cs (or, in your case, StoreProvider.vb). That is where you need to look.

The get clause of that Instance property is where the actual object is created by the Activator.CreateInstance method. You will see that the CreateIntance method requires a Type. If that Type is null, you will get an ArgumentNullException that says "value cannot be null. Parameter name:Type".

That means that Type.GetType(Globals.Settings.Store.ProviderType) that you are passing in here is probably null. You need to set a breakpoint here and debug to confirm that.

The only thing that could make this clause return null is that your application cannot find a defined type of Globals.Settings.Store.ProviderType. That would indicate a problem with your configuration settings or classes.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 16th, 2010, 04:30 PM
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee:

When I get to the Type.GetType(Globals.Settings.Store.ProviderType) in the CreateInstance Property the and check the value of the Globals.Settings.Store.ProviderType in the immediate window it says
Settings is not a member of Globals, even though all of the Globals.setting.Store properties are displayed in Intellisense.

Here is the contents of my Web.Config as it relates to these elements:

<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensions SectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGro up, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptReso urceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebService sSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerial izationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileSer viceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthentica tionServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>

<section name="TheBMTStore" type="JG.BMTStore.TheBMTStoreSection"/>

</configSections>
<connectionStrings>
<add name="connBMT" connectionString="Data Source=seb2a54; Initial Catalog=BMTStore; User ID=BMTStoreUser; Password=atlas458" providerName="System.Data.SqlClient"/>
<add name="BMTStoreConnectionString" connectionString="Data Source=seb2a54;Initial Catalog=BMTStore;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

<appSettings>
<add key="connBMT.ConnectionString" value="Data Source=seb2a54;Initial Catalog=BMTStore;User ID=BMTStoreUser;Password=atlas458"/>
<add key="TheBMTStore.ConnectionString" value="Data Source=seb2a54;Initial Catalog=BMTStore;User ID=BMTStoreUser;Password=atlas458"/>
<add key="EnableCaching" value="true"/>
<add key="CacheDuration" value="600"/>
</appSettings>

<TheBMTStore defaultConnectionStringName="connBMT" >
<contactForm mailTo="Phi.eSupply.Request@ssa.gov"/>
<store businessEmail="Phi.eSupply.Request@ssa.gov" providerType="JG.BMTStore.DAL.SQLClient.SqlStorePr ovider" />
</TheBMTStore>

I added the providerType to the store element

Here is the Globals.vb Class:

Imports System.Web.Configuration
Imports Microsoft.VisualBasic
Namespace JG.BMTStore
Public NotInheritable Class Globals
Public Shared ReadOnly Settings As TheBMTStoreSection = _
CType(WebConfigurationManager.GetSection("TheBMTSt ore"), TheBMTStoreSection)

End Class

End Namespace

In the ConfigSection.vb I have Classes defined for the TheBMTStoreSection, ContactFormElement and the StoreElement and an empy class named ConfigSection. The StoreElement is built from the TheBMTStoreSection property store.

Can you spot anything that wrong?
 
Old February 16th, 2010, 05:23 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Well, one thing I see is that you're attempting to access Globals statically, but the Globals class is not marked as static (it's also sealed, which is a bit strange).

Try

Public Shared Class Globals
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 16th, 2010, 05:33 PM
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried the declare the Global class as "Public Shared" and get the message that "Classes can not be declared as Shared".
 
Old February 16th, 2010, 05:58 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Sorry, my VB is pretty rusty.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 17th, 2010, 09:10 AM
Registered User
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Lee:

Thanks for taking some much of your time to assist me.

You suggested hard coding the provider in the SqlstoreProvider.

"You will need to do that for this to work. Otherwise, if you don't require the ability to swap put providers, you could just hard-code the provider into the CreateInstance method."

I don't require the ability to swap providers.

I guess my question is how would you hard code the provider into the CreateInstance method?

I've tried several things here without success.
 
Old February 17th, 2010, 03:44 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Something like this... like I said, my VB is a tad rusty.

Code:
Public Shared ReadOnly Property Instance() As StoreProvider
 Get
  If _instance = Nothing Then
   _instance = CType(Activator.CreateInstance(Type.GetType("JG.BMTStore.DAL.SqlClient.SqlStoreProvider")), StoreProvider)
  End If
  Return _instance
 End Get
End Property
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
SiteProvider MethodName scope? tdewey BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 8th, 2009 04:52 PM
SiteProvider Reza BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 September 7th, 2008 04:04 PM
Chapter 5 Aricles/SiteProvider question HELP PLS crazy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 March 7th, 2008 01:10 PM
SiteProvider Question zmijasu2k3 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 August 2nd, 2006 10:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.