By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

Specified cast is not valid exception when moved from v1.0 to v1.1

P: n/a
Raj
I have a c# program in which I used cast. That worked perfectly on .Net
platform 1.0. When I moved to .Net 2003, I am getting the execption
"Specified cast is not valid". I have not made any changes to the code. Is
there any difference in project settings or something else between v1.0 and
v1.1?

Thanks in advance.
--
Raj
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Raj <Ra*@discussions.microsoft.com> wrote:
I have a c# program in which I used cast. That worked perfectly on .Net
platform 1.0. When I moved to .Net 2003, I am getting the execption
"Specified cast is not valid". I have not made any changes to the code. Is
there any difference in project settings or something else between v1.0 and
v1.1?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

P: n/a
Raj

pos = new AutoMath.DPositionClass();
"Jon Skeet [C# MVP]" wrote:
Raj <Ra*@discussions.microsoft.com> wrote:
I have a c# program in which I used cast. That worked perfectly on .Net
platform 1.0. When I moved to .Net 2003, I am getting the execption
"Specified cast is not valid". I have not made any changes to the code. Is
there any difference in project settings or something else between v1.0 and
v1.1?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

P: n/a
Raj <Ra*@discussions.microsoft.com> wrote:
pos = new AutoMath.DPositionClass();


In what way is that a short but complete program?

See http://www.pobox.com/~skeet/csharp/incomplete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

P: n/a
Raj
Jon,

Thanks for your reply. Here is a code snippet. It is not complete but it is
small.

IJDPosition, iLogicalDistPort are COM interfaces defined in VC++ idl files.
DPosoition is COM class ( an ATL object ).

AutoMath.IJDPosition pos = null;
pos = new AutoMath.DPositionClass();

iLogicalDistPort.SetCenterLocation((NozzleEntities .IJDPosition)pos); //This
throws Specified cast in not valid exception.

Why cast is needed :
The iLogicalDistPort is in defined in the idl file of
NozzleEntities VC++ project. Following is the idl file:

import "AutoMath.idl";

interface IJLogicalDistPort : IDispatch
{
[id(2), helpstring("method GetCenterLocation")] HRESULT
GetCenterLocation([out,retval] IJDPosition ** ppPosition);
[id(4), helpstring("method SetCenterLocation")] HRESULT
SetCenterLocation([in] IJDPosition * pPostion);
};

library NozzleEntities
{
coclass DistribPorts
{
[default] interface IDispatch;
interface IJLogicalDistPort;
};
}

Since the object is in the type library of NozzleEntities, the method is
expecting NozzleEntities.IJDPosition as argument.

I can only create AutoMath.DPositionClass(), since that is where my
DPosition class is implemented.

I hope the scenario is clear. If not I can provide more details. Basically
I am creating an unmanaged object and calling a method on it in managed code.

My main question is, this used to work in v1.0. I haven't make any changes
except moving to v1.1. Now I get the exception. Is there any known problem
or known solution for this problem.

Thanks,
Raj

"Jon Skeet [C# MVP]" wrote:
Raj <Ra*@discussions.microsoft.com> wrote:
I have a c# program in which I used cast. That worked perfectly on .Net
platform 1.0. When I moved to .Net 2003, I am getting the execption
"Specified cast is not valid". I have not made any changes to the code. Is
there any difference in project settings or something else between v1.0 and
v1.1?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5

P: n/a
Raj <Ra*@discussions.microsoft.com> wrote:
Thanks for your reply. Here is a code snippet. It is not complete but it is
small.


Unfortunately, that still doesn't really help me, as I still can't
reproduce the problem.

Given that it's COM stuff though, I suggest you ask in the interop
group - you're more likely to get an answer there. (I'm not
particularly hot on interop, I'm afraid.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6

P: n/a
Raj
Thanks for your suggestion Jon,
I will try interop.

Raj

"Jon Skeet [C# MVP]" wrote:
Raj <Ra*@discussions.microsoft.com> wrote:
Thanks for your reply. Here is a code snippet. It is not complete but it is
small.


Unfortunately, that still doesn't really help me, as I still can't
reproduce the problem.

Given that it's COM stuff though, I suggest you ask in the interop
group - you're more likely to get an answer there. (I'm not
particularly hot on interop, I'm afraid.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.