Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

I have one application e.g.Application1.exe having two calss MyClass1 and MyClass2

C#
Class MyClass1
{
	public int i1;
	MyClass1()
	{
		i1 = 1;
	}
}

Class MyClass2
{
	public static MyClass1 Function1()
	{
		return new MyClass1();
	}
}


I have another aplication, Application2 where i have added Application1.exe reference to it. and my code is like below

C#
Class MyClass3
{
	public int i2;
}

main()
{
	MyClass3 objMyClass3 = (MyClass3) MyClass2.Function1();
}


But this is giving error.

Can any body tell me how to resolve this.

Thank you all in advance.

Regards,
Vidi
Posted

Those classes have nothing to do with each other. What would you expect it would do?

Check the link to read up on this:
http://csharp-station.com/Tutorial/CSharp/Lesson08[^]

Good luck!
 
Share this answer
 
Comments
Abhinav S 12-Mar-13 8:39am    
Correct. 5.
vidiking 12-Mar-13 8:49am    
In my application both the classes are in different name space. Application1.exe is developed in .net version 2.0 and its a remote service and Application2.exe is a wpf client application developed in 4.0. I'm using remote procedure to get some data from Application1.exe remote service.

so MyClass3 objMyClass3 = (MyClass3) MyClass2.Function1(); is giving error that type cast cannot be possible.
E.F. Nijboer 12-Mar-13 9:25am    
That doesn't change anything because you cannot simply assign one class to another. Also, your example code in the question isn't in any way related to wcf or the way communication and serialization/deserialization is handled between client and server.
You cannot simply typecast one class into another.

The only way this would work would be typecasting a base class into a derived class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900