Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InvalidCastException when using DLL file 3

Status
Not open for further replies.

JunglesMcBeef

Programmer
Sep 18, 2003
266
Hi,

I have built a dll file, and created a reference to it in a new project. Now when I go to run my new project, whenever it references the class from the DLL file I get an InvalidCastException. This doesn't happen if I add the class as an existing item to my new project, only when I reference to the dll file I built which contains it. Why is this happening?
 
Try rebuilding the old project, and make sure the dll you are referncing is the latest build.


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Ok, I tried rebuilding the dll file and the new project and that had no positive effect.

The procedures I am trying to call are just straight forward procedures, don't return any values, only starts or stops services. When it gets to those procedure, the processing stops and gives a warning message:

"InvalidCastException was unhandled" - Conversion from string "Conversion from string "Conversi" to type 'Integer' is not valid

This doesn't happen at all if I just add the vb file with the class inside it to the new project. It only happens if I reference the dll file that was built with the vb file in it, leaving it external to my new project. It has baffled me.
 
What is the return type of the function you're calling? I would guess it returns a String, and you're trying to assign it into a variable of type Integer.

You can do this, just that you need to go through the System.Convert class, or use the shared Parse method on the Integer class to do it.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Like I've already stated, there is return type, void if you like. There is no problem with the class when it is added as an item to the project, it is when I try and reference the dll file it is contained in externally that I get the problem. Am I making any sense at all?
 
I suspect that VB.NET is holding your hand when the code is used locally. If you call a DLL, then the CLR is much more involved (vs. the VB runtime support), and it's much more picky.

Like I said, compare the datatypes, and if they don't match, use a converter class to make them match. Strong typing is a virtue.

Don't forget that VB is case-insensitive, whereas the .net common type system is case-sensitive. So don't differ your names by case alone.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Good point Chip

Im also wondering if the class in question has Option Strict turned on?. If not turn it on, and resolve any cast/conversion issues this may bring up.




Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Good point about Option Strict.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top