Exception with OpenNETCF ?

G

Greenwell

I downloaded the OpenNETCF framework and tried the following:

Imports OpenNETCF.Net
Module Module1
Sub Main()
Dim a As OpenNETCF.Net.Adapter
MsgBox(a.CurrentIpAddress)
End Sub
End Module

The result is - An unhandled exception of type
'System.NullReferenceException' occurred in tst-opencf.exe

Any ideas?
 
A

Alex Feinman [MVP]

Do you want perhaps to create an instance of the Adapter class before using
it? Something like

Dim a As New OpenNETCF.Net.Adapter()
 
G

Greenwell

I tried this, it doesn't like it, I'm getting

....Module1.vb(8): 'OpenNETCF.Net.Adapter.Private Sub New(info As
OpenNETCF.Net.IP_ADAPTER_INFO)' is not accessible in this context because it
is 'Private'.


??
 
A

Alex Feinman [MVP]

Right, you are not supposed to create an instance of this class. You get an
existing instance from Networking.GetAdapters()

For Each a as Adapter in Networking.GetAdapters()
MessageBox.Show(a.CurrentIPAddress)
Next a
 
P

Peter Foot [MVP]

You can't create an Adapter directly. Instead use the Networking class to
retrieve current adapters:-

Dim ac As OpenNETCF.Net.AdapterCollection = Networking.GetAdapters()

If ac.Count > 0 Then
'first adapter
Dim a As OpenNETCF.Net.Adapter = ac(0)
MsgBox(a.CurrentIpAddress)
End If

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
G

Greenwell

It is still not working, no there is a runtime error as follows:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in mscorlib.dll
This happens, when I debug, when I set into
If ac.Count > 0 Then

Here is the complete program

'smart device, non graphical, deploy ppc
Imports OpenNETCF.Net
Module Module1
Sub Main()
Dim ac As OpenNETCF.Net.AdapterCollection = Networking.GetAdapters()
If ac.Count > 0 Then
'first adapter
Dim a As OpenNETCF.Net.Adapter = ac.Item(0) ' ac(0) didn't work
MsgBox(a.CurrentIpAddress)
End If
End Sub
End Module
 
G

Greenwell

I can't know how many adapters are returned because
to know that I need to check ac.Count and this is
throwing an exception. Has this code run o.k.
for anyone?
 
P

philip

Do I need to install the OPEN CF platform on the pocket
pc before I can run programs which use it?
 
P

Paul G. Tobey [eMVP]

Yes, it works fine, although you've told us *nothing* about what device you
are running it on. Try running the sample from the samples area. Here's
the code sequence to get a list of adapters and look at the name of each:

Dim al as OpenNETCF.Net.AdapterCollection
al = OpenNETCF.Net.Networking.GetAdapters
For Each a As OpenNETCF.Net.Adapter In al
' a.name is the name of the adapter.
Next

Paul T.
 
G

Greenwell

I have managed to find out the problem. It seems that if I
insert a wifi card and also insert the ipaq h2210 into the
cradle (cradle connected to pc , wifi unconnected) then
I get two interfaces, WLAN1 0.0.0.0., and
Serial on USB 192.168.55.101. However, if the ppc is
not in the cradle, or if the wifi card is removed, there will
be this exception I mentioned before. Good luck figuring
this out!!!
Also, Peter's notation, Dim a As OpenNETCF.Net.Adapter = ac(0)
will not work, we must use ac.item(0), or as you did with the
for each way. Again, I don't understand why the brackets do not
work, I thought this does work for lists/collections, maybee they
didn't define the () operator (or is that C++ ??).
I also noticed that the VB sample HTMLViewerVB also does't
work, well it does not even pass the editor without 3 syntax
errors, so I guess the whole OPENCF project is still buggy and
unready.
 
P

Paul G. Tobey [eMVP]

The versions of things that are available for download may be mismatched. I
run the VB sample every time I revise the code, so it *does* work. If you
have *zero* valid adapters, there was a bug which has since been fixed and
either has just dropped or will soon drop in source form. Remember that we
are making $0 off of the uses of this and all of us have real jobs which,
oddly enough, seem to take a significant amount of our time. If you'd like
to try to write the OpenNETCF.Net yourself with no help, rather than having
it pretty well done for you, you're welcome to give it a shot! There are
commercial libraries available which you can buy, too...

Paul T.
 
G

Greenwell

Just to be clear, in case someone needs to debug this bug(? ),
the exception occurs even when there is a valid adapter.
My ipaq h2210, it has built in bluetooth, plus a wifi CF
card that I purchased seperately, plus the cradle connection.
For this exception not too work both, the wifi and the cradle
need to be present, i.e. number of adpters needs to be 2,
otherwise you get an exception, I think you didn't realise
this from my previous posting, though I did say it. I'm just
saying this to help the people on this project. Sorry if I was
critical, but none of the samples I tested worked, maybe
I got a wrong version.
 
P

Paul G. Tobey [eMVP]

It's been tested with one adapter, as well as two adapters, connection with
ActiveSync, etc. It's possible that you've exposed another bug that is
associated in some way the specific pieces, however. Please give, to the
best of your ability, the precise information on the add-on hardware, as
well as the OS version on the device. Ideally, you'd actually use the
source and VS.NET would show you exactly where the problem is occurring, but
we may be able to make some progress with external information only.

Paul T.

Greenwell said:
Just to be clear, in case someone needs to debug this bug(? ),
the exception occurs even when there is a valid adapter.
My ipaq h2210, it has built in bluetooth, plus a wifi CF
card that I purchased seperately, plus the cradle connection.
For this exception not too work both, the wifi and the cradle
need to be present, i.e. number of adpters needs to be 2,
otherwise you get an exception, I think you didn't realise
this from my previous posting, though I did say it. I'm just
saying this to help the people on this project. Sorry if I was
critical, but none of the samples I tested worked, maybe
I got a wrong version.

Paul G. Tobey said:
The versions of things that are available for download may be mismatched. I
run the VB sample every time I revise the code, so it *does* work. If
you
have *zero* valid adapters, there was a bug which has since been fixed
and
either has just dropped or will soon drop in source form. Remember that we
are making $0 off of the uses of this and all of us have real jobs which,
oddly enough, seem to take a significant amount of our time. If you'd like
to try to write the OpenNETCF.Net yourself with no help, rather than having
it pretty well done for you, you're welcome to give it a shot! There are
commercial libraries available which you can buy, too...

Paul T.

Greenwell said:
I have managed to find out the problem. It seems that if I
insert a wifi card and also insert the ipaq h2210 into the
cradle (cradle connected to pc , wifi unconnected) then
I get two interfaces, WLAN1 0.0.0.0., and
Serial on USB 192.168.55.101. However, if the ppc is
not in the cradle, or if the wifi card is removed, there will
be this exception I mentioned before. Good luck figuring
this out!!!
Also, Peter's notation, Dim a As OpenNETCF.Net.Adapter = ac(0)
will not work, we must use ac.item(0), or as you did with the
for each way. Again, I don't understand why the brackets do not
work, I thought this does work for lists/collections, maybee they
didn't define the () operator (or is that C++ ??).
I also noticed that the VB sample HTMLViewerVB also does't
work, well it does not even pass the editor without 3 syntax
errors, so I guess the whole OPENCF project is still buggy and
unready.

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message Yes, it works fine, although you've told us *nothing* about what
device
you
are running it on. Try running the sample from the samples area. Here's
the code sequence to get a list of adapters and look at the name of each:

Dim al as OpenNETCF.Net.AdapterCollection
al = OpenNETCF.Net.Networking.GetAdapters
For Each a As OpenNETCF.Net.Adapter In al
' a.name is the name of the adapter.
Next

Paul T.


"Greenwell" <gdfgdfgdfg> wrote in message
I can't know how many adapters are returned because
to know that I need to check ac.Count and this is
throwing an exception. Has this code run o.k.
for anyone?

Have you tried Alex's example using For Each? How many adapters are
returned?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile
and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

"Greenwell" <gdfgdfgdfg> wrote in message
It is still not working, no there is a runtime error as follows:
An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred
in mscorlib.dll
This happens, when I debug, when I set into
If ac.Count > 0 Then

Here is the complete program

'smart device, non graphical, deploy ppc
Imports OpenNETCF.Net
Module Module1
Sub Main()
Dim ac As OpenNETCF.Net.AdapterCollection = Networking.GetAdapters()
If ac.Count > 0 Then
'first adapter
Dim a As OpenNETCF.Net.Adapter = ac.Item(0) ' ac(0) didn't work
MsgBox(a.CurrentIpAddress)
End If
End Sub
End Module


You can't create an Adapter directly. Instead use the Networking
class
to
retrieve current adapters:-

Dim ac As OpenNETCF.Net.AdapterCollection =
Networking.GetAdapters()

If ac.Count > 0 Then
'first adapter
Dim a As OpenNETCF.Net.Adapter = ac(0)
MsgBox(a.CurrentIpAddress)
End If

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile
and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

"Greenwell" <hgjghjghjghjghj> wrote in message
I tried this, it doesn't like it, I'm getting

...Module1.vb(8): 'OpenNETCF.Net.Adapter.Private Sub New(info As
OpenNETCF.Net.IP_ADAPTER_INFO)' is not accessible in this context
because
it
is 'Private'.


??




message
Do you want perhaps to create an instance of the Adapter
class
before
using
it? Something like

Dim a As New OpenNETCF.Net.Adapter()


--
Alex Feinman
---
Visit http://www.opennetcf.org
"Greenwell" <hgjghjghjghjghj> wrote in message
I downloaded the OpenNETCF framework and tried the
following:

Imports OpenNETCF.Net
Module Module1
Sub Main()
Dim a As OpenNETCF.Net.Adapter
MsgBox(a.CurrentIpAddress)
End Sub
End Module

The result is - An unhandled exception of type
'System.NullReferenceException' occurred in tst-opencf.exe

Any ideas?
 

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