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.tes t.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.tes t.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 5 1524
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.tes t.Config.Settings.msgElement.ProviderType));
could be:
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// 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.tes t.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.tes t.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
Thanks
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:AC**********************************@microsof t.com...
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.tes t.Config.Settings.msgElement.ProviderType));
could be:
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// 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.te st.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.te st.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
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).Assembl yQualifiedName 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.P roviderType);
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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:AC**********************************@microsof t.com...
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.tes t.Config.Settings.msgElement.ProviderType));
could be:
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// 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.tes t.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.tes t.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,
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.te st.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).Assembl yQualifiedName 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.P roviderType);
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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:AC**********************************@microsof t.com...
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.tes t.Config.Settings.msgElement.ProviderType));
>
could be:
>
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// 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.te st.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.te st.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
>>
>>
>>
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]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:FB**********************************@microsof t.com...
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.te st.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).Assemb lyQualifiedName 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.P roviderType);
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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:AC**********************************@microsof t.com...
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.tes t.Config.Settings.msgElement.ProviderType));
could be:
Type t =
Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// 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.te st.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.te st.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jerry Krinock |
last post by:
I've declared a class that has some std::vector data members like this:
class MyClass
{
public:
...
std::vector<Apples> apples ;
...
private:
...
|
by: Matthew Wilson |
last post by:
I need to write a function crc(msg, len) that gets a char array of
length len and then calculates the crc32 for the code. I don't
understand what's going wrong in the code I have. It goes...
|
by: Alfonso Morra |
last post by:
Hi,
I am at the end of my tether now - after spending several days trying to
figure how to do this. I have finally written a simple "proof of
concept" program to test serializing a structure...
|
by: tech guru |
last post by:
Hi,
I am doing some mathematical analysis on large numbers in C. The same
code runs perfectly in Windows but produces unpredictable results in
Unix (like negative numbers or very very big...
|
by: coala |
last post by:
My visual studio crashes when I attach to a process (i.e. Excel) so I
cannot debug. Would anyone have any advice on what I can do/I am doing
wrong please?
I have installed all the latest...
|
by: RallyDSM |
last post by:
Pre STory - I've had a lot of problems with this program, and I just
added the last part of it (the add item code) and now an older part of
the program crashes.
Public Structure Stocks
Public...
|
by: linq936 |
last post by:
Hi,
My program crashes on the following code,
void lower(char* src, char* ret){
while ( src ) {
char c = tolower(*src);
*ret = c; <----------------------------- crash here
++ret;
++src;
}
|
by: Mohamed Mansour |
last post by:
Hey there, this will be somewhat a long post, but any response is
appreciated!
I have done many PInvoke in the past from C++ to C#, but I did PInvoke
within C# not C++/CLI.
Can someone explain...
|
by: Tommy |
last post by:
struct stat *stats IF_LINT (= 0);
I don't know why "IF_LINT (= 0)" is needed ?
Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src
Thanks!
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| | |