class convertion compilation error

H

hs

I have a ClassLibrary(ClassLibrary1) with 2 classes (MyClass1, MyClass2).
(one inherits a DataSet, and the other requires a DataSet in its
constructor).

My Winform project and Asp.Net Web service both reference my
ClassLibrary1.dll.

My webservice has 2 methods (one returns MyClass1, the other MyClass2).

I keep getting compilation error -

Cannot implicitly convert Cannot implicitly convert type
'TestBed.localhost.MyClass1' to 'ClassLibrary1.MyClass1'

for this line of code -

MyClass1 mc = ws.GetMyClass1(); //ws = webservice

Any Help appreciated.
 
H

hs

Found the answer. (not sure why though)
I was doing -

TestBed.localhost.Service1 ws = new TestBed.localhost.Service1();
MyClass1 mc = ws.GetMyClass1();

should be -
TestBed.localhost.Service1 ws = new TestBed.localhost.Service1();
TestBed.localhost.MyClass1 mc = ws.GetMyClass1();
 
T

Tian Min Huang

Hello,

The error message showed the reason. :)

After adding reference the web service, the return type of ws.GetMyClass1()
is TestBed.localhost.MyClass1. It is not ClassLibrary1.MyClass1. Yes, we
know that the two classes are the same. However, for the compiler, it has
no knowledge of it. What it knows is that these two classes have the same
name but belong to different namespaces. So it feels that they are
different classes. That is why you got that error message.

Did this answer your question?

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top