473,387 Members | 1,790 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,387 software developers and data experts.

Weird type problem

I have a very strange typing problem:

There is the following class

Public Class MyBaseClass
Implents MyInterface

Public Property MyProperty As MyClass implements MyInterface.MyProperty
...
End Class

I want to execute a method that uses the MyProperty from the MyBaseClass. So I made some tries to achieve this:

Try 1

public sub myMethod(argument as MyInterface)
dim MyObject as MyClass = argument.MyProperty
end sub

When I call the method I get the following exception: MissingMethodException (although the watch and immediate window gave me access to the property)

Try 2
When I define the method as follows (option strict is off):

public sub myMethod(argument as object)
dim MyObject as MyClass = CType(argument.MyProperty, MyClass)
end sub

I don't get the MissingMethodException anymore, but now I get the InvalidCastException (although I can perform the CType correctly in the watch and immediate window)

Try 3
When I define the method as follows (option strict is off):

public sub myMethod(argument as object)
dim MyObject as MyClass
If TypeOf argument.MyProperty Is MyClass Then
MyObject = CType(argument.MyProperty, MyClass)
End If
end sub

Now the CType is never performed and now there is the best of all: when I set the a breakpoint on the TypeOf line, then the watch window tells me the expression is true, but in the code window the expression is false, because it doesn't perform the CType.

Does anyone know what to do ????
Thanks in advance
Ewald Hofman
Nov 20 '05 #1
4 1156
"Ewald Hofman" <eh*@logis-info.nl> schrieb
When I define the method as follows (option strict is off):


First switch on option strcit. Otherwise it can be hard to find an error.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
That makes no difference.

Design-time (or compile time) everything is ok. It goes wrong when I'm in
run-time. The description in the MissingMethodException is 'dynamically
binding', but I'm not, because the complete code is based on early-binding.
Nov 20 '05 #3
* "Armin Zingler" <az*******@freenet.de> scripsit:
When I define the method as follows (option strict is off):


First switch on option strcit. Otherwise it can be hard to find an error.


You forgot:

Then switch off the HTML mode in your newsreader.

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
When I define the method as follows (option strict is off):


First switch on option strcit. Otherwise it can be hard to find an
error.


You forgot:

Then switch off the HTML mode in your newsreader.

;-)


As long as HTML mode is switched off in _my_ news_reader_, I don't care
whether _his_ news_writer_ uses HTML mode.

;-)
--
Armin

Nov 20 '05 #5

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

Similar topics

3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
0
by: cxw0106 | last post by:
Hello, I have some weird problem with the FileSystemWatcher. I have developed an application that monitors a network directory for file changes of a certain file type. The program runs well for...
0
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of...
2
by: Todd A. Anderson | last post by:
Hi...any help would be appreciated. Kind of a weird scenario but I have foo's that point to bars and whenever anybody tries to use a foo as a pointer I want it typed as a baz * and likewise if...
2
by: Scott Reynolds | last post by:
I am having a problem exposing a class inherited from the collection base class as a webservice. If I expose the collection on a web page all works well and I am very happy. However when I try and...
14
by: Nak | last post by:
Hi there, It's probably me being weird more than the function but I'm having problems with it doing as it should. I have a C++ application with 2 resources of custom types, RT_INIFILE @...
3
by: aling | last post by:
Execute following T-SQL within Queary Analyzer of SQL Server 2000: ======================================= DECLARE @dTest DATETIME SET @dTest='2001-1-1 1:1:1:991' SELECT @dTest SET...
10
by: Ben | last post by:
Hi, i have a weird problem and i don't know who is responsible for this: IIS, excel or asp.net. My problem: we use an asp.net 2.0 application under IIS 6.0 (server 2003 sp2) which must write...
16
by: Bill Nguyen | last post by:
I'm running into a very weird problem regarding subtraction. Subtraction behaves as if it's an addition in the below sub txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0") ...
2
by: kigoobe | last post by:
I am having a very weird issue here, a simple form submit not working. Trying for several hours now ... must be something stupid ... help appreciated. First, the html - <form id="formFinale"...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.