Without knowing exactly what exception you're getting it's hard to say for sure what's going wrong.
But this line
svalue = type.GetProperty(property.Name).GetValue(Object1, null).ToString();
Will at least fail if:
- 1. The value of the property is
null
as the call to ToString
will then cause a NullReferenceException
. - 2. The property is an indexer property (it's likely to throw an exception)
Hope this helps,
Fredrik