Datacontracts property getter running twice
Posted
by user321426
on Stack Overflow
See other posts from Stack Overflow
or by user321426
Published on 2010-04-20T15:04:47Z
Indexed on
2010/04/20
15:33 UTC
Read the original article
Hit count: 455
I have a set of data contracts that act as wrappers to base classes that we wish to expose. A quick example is:
[DataMember]
public List<decimal> Points
{
get
{
return sourceObject.ListPoints();
}
private set{}
}
We have some other properties that we have to massage the data first (we are converting object graphs and need to guard against circular references).
The issue that we are seeing is that this getter will fire twice, once within the service operation, then again during serialization. This is causing two problems:
- We manually add to collections, since this is running twice the collections are filled with dupes.
- If an exception is thrown during the second run, it happens outside of the try/catch in the operation, and does not throw a fault. The service throws a cryptic timeout message, and the only way to see the error is via WCF trace logs.
© Stack Overflow or respective owner