473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

VS2003 to VS2005 Conversion

Hi All,



I am in the process of converting a VS 2003 project to VS 2005 project (VB.NET Class Library).



It gives the error in TypeOf and DirectCast statements. It was working perfectly under VS2003.



Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)

If TypeOf ctl Is DropDownList Then

DirectCast(ctl, DropDownList).Items.Clear()

End If

End Sub



1) The error is Expression of type 'System.Web.UI.HtmlControls.HtmlControl' can never be of type 'System.Web.UI.WebControls.DropDownList'.

2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot be converted to 'System.Web.UI.WebControls.DropDownList'



How I can avoid these errors, I tried changing the Option Strict option to Off. I cannot change the code because the TypeOf and DirectCast statements are used in more than 200 places.



Thanks & Regards,

Sam



Jan 12 '06 #1
17 2543
"Samuel" <sa****@photoninfotech.com> schrieb:
I am in the process of converting a VS 2003 project to VS 2005 project
(VB.NET Class Library).

It gives the error in TypeOf and DirectCast statements. It was working
perfectly under VS2003.

Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)
If TypeOf ctl Is DropDownList Then
DirectCast(ctl, DropDownList).Items.Clear()
End If
End Sub

1) The error is Expression of type
'System.Web.UI.HtmlControls.HtmlControl'
can never be of type 'System.Web.UI.WebControls.DropDownList'.


Which is true. 'DropDownList' does not inherit from 'HtmlControl', not even
in .NET 1.1. You may want to use 'WebControls.WebControl' instead of
'HtmlControls.HtmlControl'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 12 '06 #2
"Samuel" <sa****@photoninfotech.com> schrieb
Hi All,

I am in the process of converting a VS 2003 project to VS 2005
project (VB.NET Class Library).

It gives the error in TypeOf and DirectCast statements. It was
working perfectly under VS2003.

Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)

If TypeOf ctl Is DropDownList Then

DirectCast(ctl, DropDownList).Items.Clear()

End If

End Sub

1) The error is Expression of type
'System.Web.UI.HtmlControls.HtmlControl' can never be of type
'System.Web.UI.WebControls.DropDownList'.

2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot
be converted to 'System.Web.UI.WebControls.DropDownList'

How I can avoid these errors, I tried changing the Option Strict
option to Off. I cannot change the code because the TypeOf and
DirectCast statements are used in more than 200 places.


DropDownList is not derived from HtmlControl, thus you can not cast this
way. Why do you think you can? A HtmlControl does not have an Items
property. The classes derived from HtmlControl are

System.Web.UI.HtmlControls.HtmlContainerControl
System.Web.UI.HtmlControls.HtmlImage
System.Web.UI.HtmlControls.HtmlInputControl

ctl can point to one of these objects, but /never/ to a DropDownList object.

Armin

Jan 12 '06 #3
But it was working in VS2003. Is it possible to make the code to work in
VS2005 ?

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Samuel" <sa****@photoninfotech.com> schrieb
Hi All,

I am in the process of converting a VS 2003 project to VS 2005
project (VB.NET Class Library).

It gives the error in TypeOf and DirectCast statements. It was
working perfectly under VS2003.

Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)

If TypeOf ctl Is DropDownList Then

DirectCast(ctl, DropDownList).Items.Clear()

End If

End Sub

1) The error is Expression of type
'System.Web.UI.HtmlControls.HtmlControl' can never be of type
'System.Web.UI.WebControls.DropDownList'.

2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot
be converted to 'System.Web.UI.WebControls.DropDownList'

How I can avoid these errors, I tried changing the Option Strict
option to Off. I cannot change the code because the TypeOf and
DirectCast statements are used in more than 200 places.


DropDownList is not derived from HtmlControl, thus you can not cast this
way. Why do you think you can? A HtmlControl does not have an Items
property. The classes derived from HtmlControl are

System.Web.UI.HtmlControls.HtmlContainerControl
System.Web.UI.HtmlControls.HtmlImage
System.Web.UI.HtmlControls.HtmlInputControl

ctl can point to one of these objects, but /never/ to a DropDownList
object.

Armin

Jan 12 '06 #4
Herfried,

I'm interested in how you think this could have been working perfecting for
the OP under VS2003.

Kerry Moorman
"Herfried K. Wagner [MVP]" wrote:
"Samuel" <sa****@photoninfotech.com> schrieb:
I am in the process of converting a VS 2003 project to VS 2005 project
(VB.NET Class Library).

It gives the error in TypeOf and DirectCast statements. It was working
perfectly under VS2003.

Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)
If TypeOf ctl Is DropDownList Then
DirectCast(ctl, DropDownList).Items.Clear()
End If
End Sub

1) The error is Expression of type
'System.Web.UI.HtmlControls.HtmlControl'
can never be of type 'System.Web.UI.WebControls.DropDownList'.


Which is true. 'DropDownList' does not inherit from 'HtmlControl', not even
in .NET 1.1. You may want to use 'WebControls.WebControl' instead of
'HtmlControls.HtmlControl'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 12 '06 #5
"Samuel" <sa****@photoninfotech.com> schrieb:
But it was working in VS2003. Is it possible to make the code to work in
VS2005 ?


I doubt that the code works in VS.NET 2003. The inheritance hierarchy
didn't change. Maybe you forgot to turn on 'Option Strict' in VS.NET 2003?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 12 '06 #6
"Kerry Moorman" <Ke**********@discussions.microsoft.com> schrieb:
I'm interested in how you think this could have been working perfecting
for
the OP under VS2003.


That's what I am wondering about too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 12 '06 #7
"Samuel" <sa****@photoninfotech.com> schrieb
But it was working in VS2003. Is it possible to make the code to
work in VS2005 ?

Have you tried it in VS2003? I'm pretty sure it does not work.
Armin
Jan 12 '06 #8
Armin,

Have you tried it in VS2003? I'm pretty sure it does not work.

Did you try it, I tried it there was no error given.

web.ui.htmlcontrols derive from web.ui.controls

And than I stopped because there is a lot possible as well with html control
however AFAIK not so well documented. Therefore I am currious if you have
checked it really deep..
..
Cor
Jan 12 '06 #9
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb

Have you tried it in VS2003? I'm pretty sure it does not work.
Did you try it,


No. To check this, looking at the object browser should be sufficient. :-) I
was not able to test it because I failed in assigning a DropDownList to a
variable declared as HtmlControl.
I tried it there was no error given. web.ui.htmlcontrols derive from web.ui.controls
Right. Inheritance hierarchiy:

System.Web.UI.HtmlControls.HtmlControl
System.Web.UI.Control
System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.ListControl
System.Web.UI.WebControls.WebControl
System.Web.UI.Control
As you see, you can not cast HtmlControls.HtmlControl to DropDownList
because DropDownList is not derived from HtmControl.

And than I stopped because there is a lot possible as well with html
control however AFAIK not so well documented. Therefore I am
currious if you have checked it really deep..


Yes, I checked the object browser really deep.
Armin

Jan 12 '06 #10
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb
Did you try it, I tried it there was no error given.


I forgot: How did you try it?

Armin
Jan 12 '06 #11
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
Have you tried it in VS2003? I'm pretty sure it does not work.
Did you try it, I tried it there was no error given.


I didn't try it, but I am sure the problem is that the warning is simply
missing in VS.NET 2003 and thus the code compiles but doesn't work as
expected because the 'TypeOf...Is' condition is never met. VB 7.* lets you
write and compile

\\\
Dim f As Form
If TypeOf f Is String Then
MsgBox("Bla")
End If
///

although the condition will never be true because a variable of type 'Form'
cannot reference a 'String' object.
web.ui.htmlcontrols derive from web.ui.controls


Both are namespaces, so there is no "is-a" relation between them at all. As
said in other messages, 'HtmlControl' is not derived from 'WebControl' and
vice versa.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 12 '06 #12
I just dragged the coded in a webproject (2003) and it did give no error.

Than I pushed F1 (not serious I have searched for it on MSDJ) and saw that
they both derive from ui.web.control however "items" is not a direct member
from that and that did confuse me. However to test this I would have to do
as I wrote and that confuses me every time even more..

Cor
Jan 13 '06 #13
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb
I just dragged the coded in a webproject (2003) and it did give no
error.

Than I pushed F1 (not serious I have searched for it on MSDJ) and
saw that they both derive from ui.web.control however "items" is not
a direct member from that and that did confuse me. However to test
this I would have to do as I wrote and that confuses me every time
even more..

What's your conclusion now?
Armin
Jan 13 '06 #14
>
What's your conclusion now?

As written by you and Herfried, what can I conclude more.

Cor
Jan 13 '06 #15
"Samuel" <sa****@photoninfotech.com> schrieb:
Attached herewith the 2003 project files and 2005 project files. Now I
think
you will agree that the code will compile with 2003 and not with 2005.


I've never said the code won't compile in VS.NET 2003. I only said it won't
work as expected.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 13 '06 #16
Samuel,
PMFJI.

| But it was working in VS2003.
Compiling yes, working (aka executing) we all doubt it!

| Is it possible to make the code to work in
| VS2005 ?
No, for the reasons stated.

Did the Items.Clear method in VS2003 ever get called for a DropDownList?
Have you walked through your code in VS 2003 & verified the code (inside the
If) actually executes?

I suspect in VS2003 you effectively had:

Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)

End Sub

i.e. Although the code compiles in VS 2003, the statement never executed as
ctl could never be a DropDownList!

VS 2005 is much better at catching coding errors such as this, that may
appear correct when you type them, however the code won't actually execute.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Samuel" <sa****@photoninfotech.com> wrote in message
news:e6**************@tk2msftngp13.phx.gbl...
| But it was working in VS2003. Is it possible to make the code to work in
| VS2005 ?
|
| "Armin Zingler" <az*******@freenet.de> wrote in message
| news:%2****************@TK2MSFTNGP09.phx.gbl...
| > "Samuel" <sa****@photoninfotech.com> schrieb
| >> Hi All,
| >>
| >>
| >>
| >> I am in the process of converting a VS 2003 project to VS 2005
| >> project (VB.NET Class Library).
| >>
| >>
| >>
| >> It gives the error in TypeOf and DirectCast statements. It was
| >> working perfectly under VS2003.
| >>
| >>
| >>
| >> Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl)
| >>
| >> If TypeOf ctl Is DropDownList Then
| >>
| >> DirectCast(ctl, DropDownList).Items.Clear()
| >>
| >> End If
| >>
| >> End Sub
| >>
| >>
| >>
| >> 1) The error is Expression of type
| >> 'System.Web.UI.HtmlControls.HtmlControl' can never be of type
| >> 'System.Web.UI.WebControls.DropDownList'.
| >>
| >> 2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot
| >> be converted to 'System.Web.UI.WebControls.DropDownList'
| >>
| >>
| >>
| >> How I can avoid these errors, I tried changing the Option Strict
| >> option to Off. I cannot change the code because the TypeOf and
| >> DirectCast statements are used in more than 200 places.
| >
| > DropDownList is not derived from HtmlControl, thus you can not cast this
| > way. Why do you think you can? A HtmlControl does not have an Items
| > property. The classes derived from HtmlControl are
| >
| > System.Web.UI.HtmlControls.HtmlContainerControl
| > System.Web.UI.HtmlControls.HtmlImage
| > System.Web.UI.HtmlControls.HtmlInputControl
| >
| > ctl can point to one of these objects, but /never/ to a DropDownList
| > object.
| >
| >
| >
| > Armin
|
|
Jan 13 '06 #17

CCSBBT
CC****@bbt.org

*** Sent via Developersdex http://www.developersdex.com ***
May 2 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jarod | last post by:
Hey In VS2003 and VS2005 are tabs with code for example myclass.cs and I have tab name myclass.cs. Is there any shortcut that closes such tab ? Jarod
3
by: Ashok | last post by:
Hi All i m new to this group. Can you give me difference between Visual Studio 2000 and Visual Studio 2003 and Visual Studio 2005? Thanks
1
by: MartinS | last post by:
Have upgraded to VS2005 Standard edition (from 2003), and the first task was to convert an existing web project, get it working and then start coding using some of the new functionality of ASP .NET...
3
by: Claire | last post by:
Im transferring a visual studio 2003 project to Visual Studio 2005. The solution includes a windows installation project. With 2003 creating the setup got complicated with the crystal reports part...
6
by: =?Utf-8?B?SGFycnkgVg==?= | last post by:
I wrote a C# Windows app using VS2003 to read selected text files and write the data to 3 tables in an Access database. After "upgrading" to VS2005, I tried to add a feature and rebuild - what a...
2
by: =?Utf-8?B?UGF1bA==?= | last post by:
This is probably not the correct forum but not sure where to post this. I have a dell pc 2.4 gig intel processor, 1 gig ram, and am runing sql2005 and have vs 2003 and vs2005 installed plus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.