Apparently the problem is that it breaks in the foreach loop after finding NetTiersServiceSection, but when it returns the get { return (ProviderSettingsCollection)base["providers"]; from NetTiersServiceSection class, the provider count is = 0. I don't know how this part really works, but it seem to be the problem.
Here is the error:
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.NullReferenceException: Object reference not set to an instance of an object.Source Error:
Line 74: _providers = new NetTiersProviderCollection(); Line 75: Line 76: ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(NetTiersProvider)); Line 77: _provider = _providers[section.DefaultProvider]; Line 78:
Source File: c:\C_WH\WareHouse2\App_Code\DAL\NetTier\NetTier.DAL\DataRepository.cs Line: 76 Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] NetTier.DAL.DataRepository.LoadProviders() in c:\C_WH\WareHouse2\App_Code\DAL\NetTier\NetTier.DAL\DataRepository.cs:76 NetTier.DAL.DataRepository.get_ProductsProvider() in c:\C_WH\WareHouse2\App_Code\DAL\NetTier\NetTier.DAL\DataRepository.cs:302 WareHouse.DAL.DataObjects.SqlServer.SqlServerProductDao.GetProducts() in c:\C_WH\WareHouse2\App_Code\DAL\DataObjects\SqlServer\SqlServerProductDao.cs:58 WareHouse.BLL.Facade.ProductFacade.GetProducts() in c:\C_WH\WareHouse2\App_Code\BLL\Facade\ProductFacade.cs:32 [TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +296 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17 System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676 System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2664 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99 C1.Web.C1WebGrid.C1WebGrid.DataBind(Boolean keepGroups) +280 C1.Web.C1WebGrid.C1WebGrid.DataBind() +39 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +100 System.Web.UI.Control.EnsureChildControls() +134 System.Web.UI.Control.PreRenderRecursiveInternal() +109 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4437
============================================================================Here is the the code for DataRepository:
if (_provider == null)
{
#region Find NetTiersServiceSection
// Get a reference to the <netTiersService> section
//NetTiersServiceSection section = (NetTiersServiceSection)WebConfigurationManager.GetSection("netTiersService");
Configuration config = null;
// load specific config file
if ( HttpContext.Current != null )
config = WebConfigurationManager.OpenWebConfiguration("~");
}
else
string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.Replace(".config", "").Replace(".temp", "");
config = ConfigurationManager.OpenExeConfiguration(configFile);
// find the specific NetTiersServiceSection for this assembly
foreach ( ConfigurationSection temp in config.Sections )
if ( temp is NetTiersServiceSection )
section = temp as NetTiersServiceSection;
break;
#endregion Find NetTiersServiceSection
// Load registered providers and point _provider to the default provider
_providers = new NetTiersProviderCollection();
ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(NetTiersProvider));
_provider = _providers[section.DefaultProvider];
throw new ProviderException("Unable to load default NetTiersProvider");
========================================================================
This is the NetTierServiceSection that should be picking up the provider
public class NetTiersServiceSection : ConfigurationSection
/// <summary>
/// Gets the providers.
/// </summary>
/// <value>The providers.</value>
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers
get { return (ProviderSettingsCollection)base["providers"]; }
/// Gets or sets the default provider.
/// <value>The default provider.</value>
[StringValidator(MinLength = 1)]
[ConfigurationProperty("defaultProvider", DefaultValue = "SqlNetTiersProvider")]
public string DefaultProvider
get { return (string)base["defaultProvider"]; }
set { base["defaultProvider"] = value; }
Here is the code for my web.config which has the NetTierSection:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="netTiersService" type="NetTier.DAL.Bases.NetTiersServiceSection, NetTier.DAL"/>
</configSections>
<connectionStrings>
<remove name="aspnetdbConnectionString"/>
<add name="aspnetdbConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="WareHouseConnectionString" connectionString="Data Source=PROB001\SQL2005TEST;Initial Catalog=WareHouse;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings/>
<system.web>
<membership defaultProvider="LocalMembershipProvider">
<providers>
<add connectionStringName="aspnetdbConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="LocalMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>
</providers>
</membership>
</system.web>
<netTiersService defaultProvider="SqlNetTiersProvider">
<add name="SqlNetTiersProvider" type="NetTier.DAL.SqlClient.SqlNetTiersProvider, NetTier.DAL.SqlClient"
useStoredProcedure="true" connectionStringName="WareHouseConnectionString" applicationName="WareHouseWeb" providerInvariantName="System.Data.SqlClient"/>
</netTiersService>
</configuration>
Has anyone seen this problem or see something obvious. This has been driving me Nuts for about 3 days now.
Thanks
Nick
Nick,
Check IIS Manager and make sure that your virtual IIS directory is setup as an application (Under Directory tab there is a section called Application Settings)
Thanks,Michael
nickpatel wrote:I am getting an error saying "Object reference not set to an instance of an object". Apparently the problem is that it breaks in the foreach loop after finding NetTiersServiceSection, but when it returns the get { return (ProviderSettingsCollection)base["providers"]; from NetTiersServiceSection class, the provider count is = 0. I don't know how this part really works, but it seem to be the problem.
Mike Shatny--------------------------------------------------------------Member of the .netTiers team http://www.nettiers.com--------------------------------------------------------------
Thanks for anwering back. I did check and it is under application settings. Infact, I even deleted the virtual directory from IIS and then recreated the Vitural Directory, but it still has the same message.
thanks
Robert Hinojosa ------------------------------------- Member of the Codesmith Tools, .netTiers, teams http://www.nettiers.com-------------------------------------
I did the break points and been through the code unable to understand why its behaving this way. Here is what each break points yielded
================================================================
config = WebConfigurationManager.OpenWebConfiguration("~);
showed following values:
config = {System.Configuration.Configuration}
When I put break point below, it went to NetTier.DAL.Bases.NetTiersServiceSection returned ProviderSettingsCollection value as show (By the way, it only enters NetTier.DAL.Bases.NetTiersServiceSection in the NetTiersServiceSection.cs class once after I have opened VS2005 otherwise it won't even go there when I restart the debugger. If I open and close VS2005 it will enter it). The Count for (ProviderSettingsCollection)base["providers"] was 0
if (temp is NetTiersServiceSection)
ProviderSettingsCollection = System.Configuration.ProviderSettingsCollection //value
In the if (temp is NetTiersServiceSection) it never hit the code that says section = temp as NetTierServiceSection
section = temp
so my section = null
The _Provider seems to show _providers = {NetTier.DAL.Bases.NetTiersProviderCollection}
The part where I checked the web.config and it is NetTier.DAL.
thanksNick
What i meant is to verify if you have application name set for your virtual directory (looks like following line of code can't pick up the web.config at the root of the project WebConfigurationManager.OpenWebConfiguration("~");)
See the attach image where the application name is set
nickpatel wrote: Thanks for anwering back. I did check and it is under application settings. Infact, I even deleted the virtual directory from IIS and then recreated the Vitural Directory, but it still has the same message. thanks Nick
Hi Robert,
Could it be that the config that is found is located in the different location (rather then project root location)?
Michael
Well, in webconfig I have
<
</
and
The type in NetTiersService starts with NetTier.DAL
The project explorer shows: NetTier.DAL and NetTier.DAL.sqlClient folders.
The version of template for NetTiers says
<%-- * $Id: NetTiers.cst,v 1.19 2006/03/07 09:51:43 jroland Exp $ * Last modified by $Author: goofsr $ * Last modified at $Date: 2006-05-24 03:22:50 +0200 (mer., 24 mai 2006) $ * $Revision: 188 $
Description: NetTiers main templates. Internally call sub templates to genereate entities and dal. Originally written By Ryan Hurdon ReWritten and maintained by John Roland since Oct. 2004--%>
I did move my project from C:\Documents and Settings\pateln.PROB\My Documents\Visual Studio 2005\WebSites\WH\WareHouse to C:\C_WH. The application name is correct as you showed me in your picture. The local path is correct also. By the way how did you get the picture into the posting. Maybe I can show you how my IIS and Explorer looks like.
Here is how the explorer looks like showing I have the right NetTier names
In the explorer, the DataRepository.cs resides in C:\C_WH\WareHouse2\App_Code\DAL\NetTier\NetTier.DAL directory. The NetTiersServiceSection.cs seems to reside in C:\C_WH\WareHouse2\App_Code\DAL\NetTier\NetTier.DAL\Bases. When I ran the template, this is where it put it. Is there something I should change in the <section name> to correct this? Here is the view of VS2005 explorer: