Odd assignment bug

G

Guest

VB.NET2005 WinXP SP2

I have some code that looks like:-

with _state
....
.data =GetData()
....
end with

where .data is a DataTable

this code has worked fine for 2 weeks

now however although GetData returns 15 rows .data always has rows.count =0

If I change the code to:-

with _state
....
_state.data =GetData()
....
end with

i.e. ignore the With, the code works again

See also this:-

with _state
....
dim dt as DataTable =GetData()
.data=dt 'this fails
_state.data=dt 'this succeeds
....
end with

any Ideas?

Guy
 
G

Guest

guy said:
VB.NET2005 WinXP SP2

I have some code that looks like:-

with _state
...
.data =GetData()
...
end with

where .data is a DataTable

this code has worked fine for 2 weeks

now however although GetData returns 15 rows .data always has rows.count =0

If I change the code to:-

with _state
...
_state.data =GetData()
...
end with

i.e. ignore the With, the code works again

See also this:-

with _state
...
dim dt as DataTable =GetData()
.data=dt 'this fails
_state.data=dt 'this succeeds
...
end with

any Ideas?

Guy
further to this in the same With block

For i as integer=0 to .data.rows.count
dostuff
next

this now fails to enter the loop despite .data.rows.count being = 15
however

For i as integer=0 to _state.data.rows.count
dostuff
next

works correctly!

And yes I have powered the box off and on!

Guy
 
G

Guest

This is really bizzare!

The loop below does not get entered

with _state
_state.data=getdata
For i as integer=0 to .data.rows.count
dostuff
next
end with

The loop below does get entered

with _state
.data=getdata
_state.data=getdata
For i as integer=0 to .data.rows.count
dostuff
next
end with

and I get a null reference exception itin The 'For' line despite
..data.rows.count =15!

with _state
.data = nothing
_state.data=getdata
For i as integer=0 to .data.rows.count ' null reference exception here
dostuff
next
end with

Guy
 
G

Guest

Here is the relevant MSIL

for the line '.data = dt'

IL_0072: ldloc.s VB$t_ref$L0
IL_0074: ldloc.1
IL_0075: stfld class [System.Data]System.Data.DataTable
[App_Code.opcms84g]SState::adminTables

and for the line '_state.data =dt'

IL_0072: ldarg.0
IL_0073: ldfld class [App_Code.opcms84g]SState _Default::_state
IL_0078: ldloc.1
IL_0079: stfld class [System.Data]System.Data.DataTable
[App_Code.opcms84g]SState::adminTables

Guy
 
A

Armin Zingler

guy said:
This is really bizzare!

The loop below does not get entered

with _state
_state.data=getdata

Try to use "go to definition" (shortcut or context menu) in both lines at
the "_state" identifier. Does the cursor jump to the same declaration in
both cases?


Armin
 
G

Guest

I ran into a similar problem a long while back with the VB6 Printer object.
'With Printer', followed by '.something=whatever' failed, but
Printer.something worked. I don't recall the details. After much chasing my
tail, I fully qualified all references to Printer.

So... Maybe something is taking precedence over your 'with' statement, as I
am guessing appened to me in VB6. The name of your variable, 'data', is a
name likely to be used in other contexts, and maybe one of those contexts is
defeating the With construct.

To determine this, try:

With _state
.SomeObscureName = whatever
End with

where SomeObscureName is defined in _state and is a name that is unlikely to
be used anywhere else by anybody. If that works, then your result will be
similar to my VB6 result. In my 'with printer' construct, some things worked
and some things didn't. In your case, 'with _state', we know only that .data
does not work. Maybe it does work with a name other than '.data'. If it
does work, it would be interesting to see what the IL is.
 
G

Guest

Hi Armin,
hmmm
'go to definition' is greyed out - anywhere in the code, and intellisense
has gone away.
Intellisense went away a week ago, came back when I added a new project, and
then vanished again.

Guy
 
A

Armin Zingler

guy said:
Hi Armin,
hmmm
'go to definition' is greyed out - anywhere in the code, and
intellisense has gone away.
Intellisense went away a week ago, came back when I added a new
project, and then vanished again.

That's strange. I currently have no clue how to solve this, sorry... anybody
else?


Armin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top