Showing posts with label wrong. Show all posts
Showing posts with label wrong. Show all posts

Saturday, March 31, 2012

There is no row at position 0?

I encountered an error: There is no row at position 0.

I have no idea what went wrong. Kindly advise. Thank you!

=====================================================

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
getDetails()
End If

Dim confirmMsg As String

' On reolad
If Page.IsPostBack Then
' Set Message to Notify User
confirmMsg = "The event has been updated successfully."
'display msg
lblConfirm.Text = confirmMsg
End If

End Sub

Sub getDetails()

Dim sql1 As OleDbDataAdapter
Dim objCommand As OleDbCommand
Dim strSQLQuery As String
Dim oledbconnection1 As OleDbConnection

Dim passedID As String
passedID = Request.QueryString("EventID")

strSQLQuery = "SELECT * FROM Event WHERE EventID= '" & passedID & "'"

oledbconnection1 = New OleDbConnection(Application("connectionStr"))

objCommand = New OleDbCommand(strSQLQuery, oledbconnection1)
sql1 = New OleDbDataAdapter(objCommand)

Dim dset1 As New DataSet
sql1.Fill(dset1, "Event")

txtTitle.Text &= " " & dset1.Tables("Event").Rows(0).Item("EventTitle")

oledbconnection1.Open()
objCommand.ExecuteNonQuery()
oledbconnection1.Close()

End SubHi,

it would be nice if you also gave the relevant place where the error occured. But the times that I encountered this error message just ment exactly what it states: there is no row --> there are 0 rows returned by your query or the dataset didn't get filled.

Grz, Kris.
Debug getDetails...
-----------

Sub getDetails()

Dim sql1 As OleDbDataAdapter
Dim objCommand As OleDbCommand
Dim strSQLQuery As String
Dim oledbconnection1 As OleDbConnection
Debug your method...

Dim passedID As String
passedID = Request.QueryString("EventID")

'!!! Evaluate passedID. What does it contain? If its a valid value then continue !!!
strSQLQuery = "SELECT * FROM Event WHERE EventID= '" & passedID & "'"

'!!! Now evaluate strSqlQuery. What does it contain?? If valid continue !!!
oledbconnection1 = New OleDbConnection(Application("connectionStr"))

objCommand = New OleDbCommand(strSQLQuery, oledbconnection1)
sql1 = New OleDbDataAdapter(objCommand)

Dim dset1 As New DataSet
sql1.Fill(dset1, "Event")

txtTitle.Text &= " " & dset1.Tables("Event").Rows(0).Item("EventTitle")

End Sub

As long as it all passed ok. That should return a resultset.

Saying that I,ve not checked it syntax wise but its more fluid.

Wednesday, March 28, 2012

This application is currently offline.........

Hello All,

I got this message when I "Build" my application. What did I do wrong.

"This application is currently offline. To enable the application, remove the app_offline.htm file from the application root directory. "

Thanks

So, did you look in your Solution Explorer, find the file, and do what it said?

Thanks

Yes. I deleted the file and it works fine now.

Why and how this file is created. File says the same thing as "This application is currently offline......."


yes I m also getting this error in my application .....what can be the reason behind it and what is the resolution for this


the resolution is - find the file called 'app_offline.htm' and remove it

This code crashes, what am I doing wrong??

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??

JeffWell,
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:

Quote:

Originally Posted by

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]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

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:
>

Quote:

Originally Posted by

>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
>>
>>
>>


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:

Quote:

Originally Posted by

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]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

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:

Quote:

Originally Posted by

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:

Quote:

Originally Posted by

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:
>

Quote:

Originally Posted by

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]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

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
>>
>>
>>



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]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:FB62B8F3-8DAE-4E81-917C-935316F2CFE8@.microsoft.com...

Quote:

Originally Posted by

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:
>

Quote:

Originally Posted by

>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:
>>

Quote:

Originally Posted by

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]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.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
>>
>>
>>
>
>
>

This code crashes, what am I doing wrong??

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.msgEleme
nt.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.msgEleme
nt.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'
JeffWell,
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.msgEleme
nt.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.msgEle
ment.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.msgEle
ment.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.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]" <pbromberg@.yahoo.yabbadabbadoo.com> wrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.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.test.Config.Settings.msgEle
ment.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:
>
Type.GetType gives you the ability to get a type back from a string. You pas
s
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 th
e
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]" <pbromberg@.yahoo.yabbadabbadoo.com> wrote in
> message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.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.test.Config.Settings.msgElem
ent.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 p
ass
> 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 afte
r
> ',' in the typeName string is treated as assembly name. To make it work,yo
u
> need to specify "YourAssembly.dll" in typeName. In contrast,
> Type.GetType("System.Int32") can return type System.Int32 without mentioni
ng
> "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:
>
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]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:FB62B8F3-8DAE-4E81-917C-935316F2CFE8@.microsoft.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.test.Config.Settings.msgEl
ement.ProviderType,
> true);
> instead.
> Regards
> --
> Milosz
>
> "Peter Bromberg [C# MVP]" wrote:
>