This code crashes, what am I doing wrong????

Discussion in 'ASP .Net' started by Jeff, Apr 9, 2007.

  1. Jeff

    Jeff Guest

    ASP.NET 2.0

    This code crashes. It generate this error:
    Value cannot be null.
    Parameter name: type

    I've created some custom web.config settings and this crash is related to
    accessing theme custom settings. This code is where the crash occur:
    _instance =
    (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    This code is trying to do is to create an instance of the DAL provider,

    ************* custom web.config settings: **********************
    <configSections>
    <section name="msg" type="min.test.ConfigSection, __code"/>
    </configSections>
    <msg>
    <messages providerType="min.test.DAL.SqlServer2005"/>
    </msg>

    ********* In this code the crash occur *********
    /* This code is from the DAL class, this code is trying to create an
    instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    static public DAL Instance
    {
    get
    {
    if (_instance == null)
    _instance =
    (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    <--- code crashes here
    return _instance;
    }
    }

    ******** definition of the custom settings in web.config
    **********************
    using System;
    using System.Collections.Generic;
    using System.Configuration;

    namespace min.test
    {
    public class ConfigSection : ConfigurationSection
    {
    [ConfigurationProperty("messages", IsRequired = true)]
    public MsgElement msgElement
    {
    get { return (MsgElement)base["messages"]; }
    }

    }

    public class MsgElement : ConfigurationElement
    {
    [ConfigurationProperty("providerType", DefaultValue =
    "min.test.DAL.SqlServer2005")]
    public string ProviderType
    {
    get { return (string)base["providerType"]; }
    set { base["providerType"] = value; }
    }
    }

    }

    Any suggestions??

    Jeff
     
    Jeff, Apr 9, 2007
    #1
    1. Advertising

  2. Well,
    The exception message doesn't lie - it's telling you that you've got a null
    value, and it cannot accept it and continue.

    One way to get at this is to "take apart" your compound statement so that it
    will becom easier to set breakpoints and examine values, e.g.:

    instance =
    (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));

    could be:

    Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    // check to see if t above is null.

    instance = (DAL)Activator.CreateInstance(t);

    Peter
    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Jeff" wrote:

    > ASP.NET 2.0
    >
    > This code crashes. It generate this error:
    > Value cannot be null.
    > Parameter name: type
    >
    > I've created some custom web.config settings and this crash is related to
    > accessing theme custom settings. This code is where the crash occur:
    > _instance =
    > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > This code is trying to do is to create an instance of the DAL provider,
    >
    > ************* custom web.config settings: **********************
    > <configSections>
    > <section name="msg" type="min.test.ConfigSection, __code"/>
    > </configSections>
    > <msg>
    > <messages providerType="min.test.DAL.SqlServer2005"/>
    > </msg>
    >
    > ********* In this code the crash occur *********
    > /* This code is from the DAL class, this code is trying to create an
    > instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    > static public DAL Instance
    > {
    > get
    > {
    > if (_instance == null)
    > _instance =
    > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > <--- code crashes here
    > return _instance;
    > }
    > }
    >
    > ******** definition of the custom settings in web.config
    > **********************
    > using System;
    > using System.Collections.Generic;
    > using System.Configuration;
    >
    > namespace min.test
    > {
    > public class ConfigSection : ConfigurationSection
    > {
    > [ConfigurationProperty("messages", IsRequired = true)]
    > public MsgElement msgElement
    > {
    > get { return (MsgElement)base["messages"]; }
    > }
    >
    > }
    >
    > public class MsgElement : ConfigurationElement
    > {
    > [ConfigurationProperty("providerType", DefaultValue =
    > "min.test.DAL.SqlServer2005")]
    > public string ProviderType
    > {
    > get { return (string)base["providerType"]; }
    > set { base["providerType"] = value; }
    > }
    > }
    >
    > }
    >
    > Any suggestions??
    >
    > Jeff
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 9, 2007
    #2
    1. Advertising

  3. Jeff

    Jeff Guest

    Thanks

    Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    t gets a NULL value here. I've looked at the web.config settings and the
    code that creates the custom web.config settings and I cannot see what I'm
    doing wrong here... or maybe I'm becoming blind to my own programming
    errors. Do you see why it get NULL value??

    Jeff

    "Peter Bromberg [C# MVP]" <> wrote in
    message news:...
    > Well,
    > The exception message doesn't lie - it's telling you that you've got a
    > null
    > value, and it cannot accept it and continue.
    >
    > One way to get at this is to "take apart" your compound statement so that
    > it
    > will becom easier to set breakpoints and examine values, e.g.:
    >
    > instance =
    > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >
    > could be:
    >
    > Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    > // check to see if t above is null.
    >
    > instance = (DAL)Activator.CreateInstance(t);
    >
    > Peter
    > --
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    >
    > "Jeff" wrote:
    >
    >> ASP.NET 2.0
    >>
    >> This code crashes. It generate this error:
    >> Value cannot be null.
    >> Parameter name: type
    >>
    >> I've created some custom web.config settings and this crash is related to
    >> accessing theme custom settings. This code is where the crash occur:
    >> _instance =
    >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >> This code is trying to do is to create an instance of the DAL provider,
    >>
    >> ************* custom web.config settings: **********************
    >> <configSections>
    >> <section name="msg" type="min.test.ConfigSection, __code"/>
    >> </configSections>
    >> <msg>
    >> <messages providerType="min.test.DAL.SqlServer2005"/>
    >> </msg>
    >>
    >> ********* In this code the crash occur *********
    >> /* This code is from the DAL class, this code is trying to create an
    >> instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    >> static public DAL Instance
    >> {
    >> get
    >> {
    >> if (_instance == null)
    >> _instance =
    >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >> <--- code crashes here
    >> return _instance;
    >> }
    >> }
    >>
    >> ******** definition of the custom settings in web.config
    >> **********************
    >> using System;
    >> using System.Collections.Generic;
    >> using System.Configuration;
    >>
    >> namespace min.test
    >> {
    >> public class ConfigSection : ConfigurationSection
    >> {
    >> [ConfigurationProperty("messages", IsRequired = true)]
    >> public MsgElement msgElement
    >> {
    >> get { return (MsgElement)base["messages"]; }
    >> }
    >>
    >> }
    >>
    >> public class MsgElement : ConfigurationElement
    >> {
    >> [ConfigurationProperty("providerType", DefaultValue =
    >> "min.test.DAL.SqlServer2005")]
    >> public string ProviderType
    >> {
    >> get { return (string)base["providerType"]; }
    >> set { base["providerType"] = value; }
    >> }
    >> }
    >>
    >> }
    >>
    >> Any suggestions??
    >>
    >> Jeff
    >>
    >>
    >>
     
    Jeff, Apr 9, 2007
    #3
  4. Type.GetType gives you the ability to get a type back from a string. You pass
    a known, available type name string to it, and expect it return that type.

    If the assembly name is specified in the typeName string, Type.GetType()
    will search inside this assembly only; otherwise, it tries to find one in the
    caller assembly and then the system assembly (mscorlib.dll). Anything after
    ',' in the typeName string is treated as assembly name. To make it work,you
    need to specify "YourAssembly.dll" in typeName. In contrast,
    Type.GetType("System.Int32") can return type System.Int32 without mentioning
    "mscorlib.dll".

    Type.AssemblyQualifiedName is the right way to tell what kind of typeName
    you should provide.
    typeof(System.Data.SqlClient.SqlException).AssemblyQualifiedName equals:
    "System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
    Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
    long string will succeed in .NET 2.0.

    In .NET, namespace and the associated assembly name are not necessarily
    related. Type "System.Data.SqlClient.SqlException" is not associated with
    "System.Data.SqlClient.dll" (which does not exist).

    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Jeff" wrote:

    > Thanks
    >
    > Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    > t gets a NULL value here. I've looked at the web.config settings and the
    > code that creates the custom web.config settings and I cannot see what I'm
    > doing wrong here... or maybe I'm becoming blind to my own programming
    > errors. Do you see why it get NULL value??
    >
    > Jeff
    >
    > "Peter Bromberg [C# MVP]" <> wrote in
    > message news:...
    > > Well,
    > > The exception message doesn't lie - it's telling you that you've got a
    > > null
    > > value, and it cannot accept it and continue.
    > >
    > > One way to get at this is to "take apart" your compound statement so that
    > > it
    > > will becom easier to set breakpoints and examine values, e.g.:
    > >
    > > instance =
    > > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > >
    > > could be:
    > >
    > > Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    > > // check to see if t above is null.
    > >
    > > instance = (DAL)Activator.CreateInstance(t);
    > >
    > > Peter
    > > --
    > > Site: http://www.eggheadcafe.com
    > > UnBlog: http://petesbloggerama.blogspot.com
    > > Short urls & more: http://ittyurl.net
    > >
    > >
    > >
    > >
    > > "Jeff" wrote:
    > >
    > >> ASP.NET 2.0
    > >>
    > >> This code crashes. It generate this error:
    > >> Value cannot be null.
    > >> Parameter name: type
    > >>
    > >> I've created some custom web.config settings and this crash is related to
    > >> accessing theme custom settings. This code is where the crash occur:
    > >> _instance =
    > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > >> This code is trying to do is to create an instance of the DAL provider,
    > >>
    > >> ************* custom web.config settings: **********************
    > >> <configSections>
    > >> <section name="msg" type="min.test.ConfigSection, __code"/>
    > >> </configSections>
    > >> <msg>
    > >> <messages providerType="min.test.DAL.SqlServer2005"/>
    > >> </msg>
    > >>
    > >> ********* In this code the crash occur *********
    > >> /* This code is from the DAL class, this code is trying to create an
    > >> instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    > >> static public DAL Instance
    > >> {
    > >> get
    > >> {
    > >> if (_instance == null)
    > >> _instance =
    > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > >> <--- code crashes here
    > >> return _instance;
    > >> }
    > >> }
    > >>
    > >> ******** definition of the custom settings in web.config
    > >> **********************
    > >> using System;
    > >> using System.Collections.Generic;
    > >> using System.Configuration;
    > >>
    > >> namespace min.test
    > >> {
    > >> public class ConfigSection : ConfigurationSection
    > >> {
    > >> [ConfigurationProperty("messages", IsRequired = true)]
    > >> public MsgElement msgElement
    > >> {
    > >> get { return (MsgElement)base["messages"]; }
    > >> }
    > >>
    > >> }
    > >>
    > >> public class MsgElement : ConfigurationElement
    > >> {
    > >> [ConfigurationProperty("providerType", DefaultValue =
    > >> "min.test.DAL.SqlServer2005")]
    > >> public string ProviderType
    > >> {
    > >> get { return (string)base["providerType"]; }
    > >> set { base["providerType"] = value; }
    > >> }
    > >> }
    > >>
    > >> }
    > >>
    > >> Any suggestions??
    > >>
    > >> Jeff
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 9, 2007
    #4
  5. Jeff,

    In addition to Peter's reply, there's another way of obtaining the reference
    in ASP.NET 2.0 dynamic compilation enviroment. Please use
    System.Web.Compilation.BuildManager.GetType(min.test.Config.Settings.msgElement.ProviderType, true);
    instead.

    Regards
    --
    Milosz


    "Peter Bromberg [C# MVP]" wrote:

    > Type.GetType gives you the ability to get a type back from a string. You pass
    > a known, available type name string to it, and expect it return that type.
    >
    > If the assembly name is specified in the typeName string, Type.GetType()
    > will search inside this assembly only; otherwise, it tries to find one in the
    > caller assembly and then the system assembly (mscorlib.dll). Anything after
    > ',' in the typeName string is treated as assembly name. To make it work,you
    > need to specify "YourAssembly.dll" in typeName. In contrast,
    > Type.GetType("System.Int32") can return type System.Int32 without mentioning
    > "mscorlib.dll".
    >
    > Type.AssemblyQualifiedName is the right way to tell what kind of typeName
    > you should provide.
    > typeof(System.Data.SqlClient.SqlException).AssemblyQualifiedName equals:
    > "System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
    > Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
    > long string will succeed in .NET 2.0.
    >
    > In .NET, namespace and the associated assembly name are not necessarily
    > related. Type "System.Data.SqlClient.SqlException" is not associated with
    > "System.Data.SqlClient.dll" (which does not exist).
    >
    > -- Peter
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    >
    > "Jeff" wrote:
    >
    > > Thanks
    > >
    > > Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    > > t gets a NULL value here. I've looked at the web.config settings and the
    > > code that creates the custom web.config settings and I cannot see what I'm
    > > doing wrong here... or maybe I'm becoming blind to my own programming
    > > errors. Do you see why it get NULL value??
    > >
    > > Jeff
    > >
    > > "Peter Bromberg [C# MVP]" <> wrote in
    > > message news:...
    > > > Well,
    > > > The exception message doesn't lie - it's telling you that you've got a
    > > > null
    > > > value, and it cannot accept it and continue.
    > > >
    > > > One way to get at this is to "take apart" your compound statement so that
    > > > it
    > > > will becom easier to set breakpoints and examine values, e.g.:
    > > >
    > > > instance =
    > > > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > > >
    > > > could be:
    > > >
    > > > Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    > > > // check to see if t above is null.
    > > >
    > > > instance = (DAL)Activator.CreateInstance(t);
    > > >
    > > > Peter
    > > > --
    > > > Site: http://www.eggheadcafe.com
    > > > UnBlog: http://petesbloggerama.blogspot.com
    > > > Short urls & more: http://ittyurl.net
    > > >
    > > >
    > > >
    > > >
    > > > "Jeff" wrote:
    > > >
    > > >> ASP.NET 2.0
    > > >>
    > > >> This code crashes. It generate this error:
    > > >> Value cannot be null.
    > > >> Parameter name: type
    > > >>
    > > >> I've created some custom web.config settings and this crash is related to
    > > >> accessing theme custom settings. This code is where the crash occur:
    > > >> _instance =
    > > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > > >> This code is trying to do is to create an instance of the DAL provider,
    > > >>
    > > >> ************* custom web.config settings: **********************
    > > >> <configSections>
    > > >> <section name="msg" type="min.test.ConfigSection, __code"/>
    > > >> </configSections>
    > > >> <msg>
    > > >> <messages providerType="min.test.DAL.SqlServer2005"/>
    > > >> </msg>
    > > >>
    > > >> ********* In this code the crash occur *********
    > > >> /* This code is from the DAL class, this code is trying to create an
    > > >> instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    > > >> static public DAL Instance
    > > >> {
    > > >> get
    > > >> {
    > > >> if (_instance == null)
    > > >> _instance =
    > > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    > > >> <--- code crashes here
    > > >> return _instance;
    > > >> }
    > > >> }
    > > >>
    > > >> ******** definition of the custom settings in web.config
    > > >> **********************
    > > >> using System;
    > > >> using System.Collections.Generic;
    > > >> using System.Configuration;
    > > >>
    > > >> namespace min.test
    > > >> {
    > > >> public class ConfigSection : ConfigurationSection
    > > >> {
    > > >> [ConfigurationProperty("messages", IsRequired = true)]
    > > >> public MsgElement msgElement
    > > >> {
    > > >> get { return (MsgElement)base["messages"]; }
    > > >> }
    > > >>
    > > >> }
    > > >>
    > > >> public class MsgElement : ConfigurationElement
    > > >> {
    > > >> [ConfigurationProperty("providerType", DefaultValue =
    > > >> "min.test.DAL.SqlServer2005")]
    > > >> public string ProviderType
    > > >> {
    > > >> get { return (string)base["providerType"]; }
    > > >> set { base["providerType"] = value; }
    > > >> }
    > > >> }
    > > >>
    > > >> }
    > > >>
    > > >> Any suggestions??
    > > >>
    > > >> Jeff
    > > >>
    > > >>
    > > >>

    > >
    > >
    > >
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Apr 9, 2007
    #5
  6. Jeff

    Jeff Guest

    thank you guys, you helped me solve this problem.

    This is a bit embarrassing. I tryed to create an instance of this class:
    min.test.DAL.SqlServer2005, but this class don't exist in my project.
    min.test.DAL.SqlServer2005.SqlServer2005 is the class I needed.... I had
    forgot that I had a namespace with the same name as the class...
    anyway I changed the .SqlServer2005 namespace to SqlClient so now I'm
    accessing min.test.DAL.SqlClient.SqlServer2005

    once again, thank you

    cheers

    Jeff


    "Milosz Skalecki [MCAD]" <> wrote in message
    news:...
    > Jeff,
    >
    > In addition to Peter's reply, there's another way of obtaining the
    > reference
    > in ASP.NET 2.0 dynamic compilation enviroment. Please use
    > System.Web.Compilation.BuildManager.GetType(min.test.Config.Settings.msgElement.ProviderType,
    > true);
    > instead.
    >
    > Regards
    > --
    > Milosz
    >
    >
    > "Peter Bromberg [C# MVP]" wrote:
    >
    >> Type.GetType gives you the ability to get a type back from a string. You
    >> pass
    >> a known, available type name string to it, and expect it return that
    >> type.
    >>
    >> If the assembly name is specified in the typeName string, Type.GetType()
    >> will search inside this assembly only; otherwise, it tries to find one in
    >> the
    >> caller assembly and then the system assembly (mscorlib.dll). Anything
    >> after
    >> ',' in the typeName string is treated as assembly name. To make it
    >> work,you
    >> need to specify "YourAssembly.dll" in typeName. In contrast,
    >> Type.GetType("System.Int32") can return type System.Int32 without
    >> mentioning
    >> "mscorlib.dll".
    >>
    >> Type.AssemblyQualifiedName is the right way to tell what kind of typeName
    >> you should provide.
    >> typeof(System.Data.SqlClient.SqlException).AssemblyQualifiedName equals:
    >> "System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
    >> Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
    >> long string will succeed in .NET 2.0.
    >>
    >> In .NET, namespace and the associated assembly name are not necessarily
    >> related. Type "System.Data.SqlClient.SqlException" is not associated with
    >> "System.Data.SqlClient.dll" (which does not exist).
    >>
    >> -- Peter
    >> Site: http://www.eggheadcafe.com
    >> UnBlog: http://petesbloggerama.blogspot.com
    >> Short urls & more: http://ittyurl.net
    >>
    >>
    >>
    >>
    >> "Jeff" wrote:
    >>
    >> > Thanks
    >> >
    >> > Type t =
    >> > Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    >> > t gets a NULL value here. I've looked at the web.config settings and
    >> > the
    >> > code that creates the custom web.config settings and I cannot see what
    >> > I'm
    >> > doing wrong here... or maybe I'm becoming blind to my own programming
    >> > errors. Do you see why it get NULL value??
    >> >
    >> > Jeff
    >> >
    >> > "Peter Bromberg [C# MVP]" <> wrote in
    >> > message news:...
    >> > > Well,
    >> > > The exception message doesn't lie - it's telling you that you've got
    >> > > a
    >> > > null
    >> > > value, and it cannot accept it and continue.
    >> > >
    >> > > One way to get at this is to "take apart" your compound statement so
    >> > > that
    >> > > it
    >> > > will becom easier to set breakpoints and examine values, e.g.:
    >> > >
    >> > > instance =
    >> > > (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >> > >
    >> > > could be:
    >> > >
    >> > > Type t =
    >> > > Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
    >> > > // check to see if t above is null.
    >> > >
    >> > > instance = (DAL)Activator.CreateInstance(t);
    >> > >
    >> > > Peter
    >> > > --
    >> > > Site: http://www.eggheadcafe.com
    >> > > UnBlog: http://petesbloggerama.blogspot.com
    >> > > Short urls & more: http://ittyurl.net
    >> > >
    >> > >
    >> > >
    >> > >
    >> > > "Jeff" wrote:
    >> > >
    >> > >> ASP.NET 2.0
    >> > >>
    >> > >> This code crashes. It generate this error:
    >> > >> Value cannot be null.
    >> > >> Parameter name: type
    >> > >>
    >> > >> I've created some custom web.config settings and this crash is
    >> > >> related to
    >> > >> accessing theme custom settings. This code is where the crash occur:
    >> > >> _instance =
    >> > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >> > >> This code is trying to do is to create an instance of the DAL
    >> > >> provider,
    >> > >>
    >> > >> ************* custom web.config settings: **********************
    >> > >> <configSections>
    >> > >> <section name="msg" type="min.test.ConfigSection, __code"/>
    >> > >> </configSections>
    >> > >> <msg>
    >> > >> <messages providerType="min.test.DAL.SqlServer2005"/>
    >> > >> </msg>
    >> > >>
    >> > >> ********* In this code the crash occur *********
    >> > >> /* This code is from the DAL class, this code is trying to create an
    >> > >> instance of the DAL set in web.config - min.test.DAL.SqlServer2005
    >> > >> static public DAL Instance
    >> > >> {
    >> > >> get
    >> > >> {
    >> > >> if (_instance == null)
    >> > >> _instance =
    >> > >> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
    >> > >> <--- code crashes here
    >> > >> return _instance;
    >> > >> }
    >> > >> }
    >> > >>
    >> > >> ******** definition of the custom settings in web.config
    >> > >> **********************
    >> > >> using System;
    >> > >> using System.Collections.Generic;
    >> > >> using System.Configuration;
    >> > >>
    >> > >> namespace min.test
    >> > >> {
    >> > >> public class ConfigSection : ConfigurationSection
    >> > >> {
    >> > >> [ConfigurationProperty("messages", IsRequired = true)]
    >> > >> public MsgElement msgElement
    >> > >> {
    >> > >> get { return (MsgElement)base["messages"]; }
    >> > >> }
    >> > >>
    >> > >> }
    >> > >>
    >> > >> public class MsgElement : ConfigurationElement
    >> > >> {
    >> > >> [ConfigurationProperty("providerType", DefaultValue =
    >> > >> "min.test.DAL.SqlServer2005")]
    >> > >> public string ProviderType
    >> > >> {
    >> > >> get { return (string)base["providerType"]; }
    >> > >> set { base["providerType"] = value; }
    >> > >> }
    >> > >> }
    >> > >>
    >> > >> }
    >> > >>
    >> > >> Any suggestions??
    >> > >>
    >> > >> Jeff
    >> > >>
    >> > >>
    >> > >>
    >> >
    >> >
    >> >
     
    Jeff, Apr 9, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Asfand Yar Qazi
    Replies:
    2
    Views:
    533
    Asfand Yar Qazi
    Sep 26, 2003
  2. Ronald
    Replies:
    3
    Views:
    3,607
    Jerom
    Oct 23, 2006
  3. F. GEIGER
    Replies:
    1
    Views:
    382
    F. GEIGER
    Apr 13, 2004
  4. Curtis Zimmerman

    What am I doing wrong? -Chat server code-

    Curtis Zimmerman, Aug 27, 2006, in forum: Ruby
    Replies:
    2
    Views:
    106
    Alex Young
    Aug 27, 2006
  5. kiran
    Replies:
    12
    Views:
    1,128
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page