c# - InvalidCastException while no compile errors with upcasting -


what i'm trying convert objects web service objects compatible entity framework object. though of doing creating interface both applied web service objects & ef objects. way can cast 1 type other. @ point have following object: a, a1, b , interface iab.

the problem i'm no facing when upcast object a1 run-time error no compile errors. know why upcast isn't accepted?

public class {   //has variables & properties }  public class a1 : a, iab {   //has properties } 

note: needed create a1 extending partial class created serialization problems web service. seemed best solution.

when contacting service ask list of objects , want upcast them a1. later cast them b.

i try cast objects this:

 list<a1> alla1 = new list<a1>();  foreach (a item in retrievedlistofa)  {            alla1.add((a1)item);   } 

as don't compile errors find strange error. if check of type "a a1" never goes in if statement.

can point out me why creating problems? because object web service?

note: if method of "porting" object 1 totally absurd please give me directions how should done. first time i'm attempting this.

you don't compile errors, because (a1)item, saying compiler, know i'm doing shut up.

so if retrievedlistofa collection of , a1s, every cast a1, in fact , call a1 method on blow up.

there lots of porting methods, e.g. converter, casting not 1 of them.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -