0

How to assign same object list but in different namespace. list, list2

list = list2;

Cannot implicitly convert type System.Collections.Generic.List<namespace1.MyData> to System.Collections.Generic.List<namespace2.MyData>

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Southsouth
  • 2,659
  • 6
  • 32
  • 39
  • Can you clarify or post a bit of code? Are you just trying to copy the contents of list to list2? – Steve V. Apr 10 '11 at 03:38
  • 2
    if the type that's held by list and list2 is different (i.e. `List` and `List` you cannot do this, `namespace1.MyData` is not the same type as `namespace2.MyData` – BrokenGlass Apr 10 '11 at 03:43

2 Answers2

3

This sounds to me like a WCF proxy that has been generated and you want to reuse the existing class libraries instead of the proxy generated ones.

If this is the case, then see this answer or this answer.

Edit:

as a follow up to this, occassionally you may be in the position where you can't reuse the common class definitions (in the case of Silverlight you have to create a whole new assembly which may not be practical). If you are in this position, there is another option: the proxy generated classes are defined as partial, so you can extend them with a Clone() or Copy() method that returns the identical object from the other namespace, with the values copied over.

Community
  • 1
  • 1
slugster
  • 49,403
  • 14
  • 95
  • 145
1

If the objects can be cast to each other, you can do this, but it is looping though the lists and making a copy, it's not a direct assignment.

var newList = oldList.Cast<NewType>().ToList();
Samuel Neff
  • 73,278
  • 17
  • 138
  • 182