Skip to content

Commit 4034866

Browse files
author
Sai Krishna V
authored
Merge pull request microsoft#90 from saikrishnav/stackoverflowfixport
StackOverflowFix Port: Merge pull request microsoft#89 from saikrishnav/stackoverflowfix
2 parents cf65531 + b4bee6a commit 4034866

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Microsoft.TestPlatform.ObjectModel/TestObject.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel
1717
[DataContract]
1818
public abstract class TestObject
1919
{
20+
static TestObject()
21+
{
22+
// Do TypeConverter registrations in static constructor only to avoid multiple registrations
23+
// If we register too much, deserialization of large number of testobjects will cause StackOverflow exception
24+
TypeDescriptor.AddAttributes(typeof(Guid), new TypeConverterAttribute(typeof(CustomGuidConverter)));
25+
TypeDescriptor.AddAttributes(typeof(KeyValuePair<string, string>[]), new TypeConverterAttribute(typeof(CustomKeyValueConverter)));
26+
TypeDescriptor.AddAttributes(typeof(string[]), new TypeConverterAttribute(typeof(CustomStringArrayConverter)));
27+
}
28+
2029
#region Fields
2130

2231
/// <summary>
@@ -64,9 +73,6 @@ private List<KeyValuePair<TestProperty, object>> StoreKeyValuePairs
6473
protected TestObject()
6574
{
6675
this.store = new Dictionary<TestProperty, object>();
67-
TypeDescriptor.AddAttributes(typeof(Guid), new TypeConverterAttribute(typeof(CustomGuidConverter)));
68-
TypeDescriptor.AddAttributes(typeof(KeyValuePair<string, string>[]), new TypeConverterAttribute(typeof(CustomKeyValueConverter)));
69-
TypeDescriptor.AddAttributes(typeof(string[]), new TypeConverterAttribute(typeof(CustomStringArrayConverter)));
7076
}
7177

7278
[OnSerializing]

0 commit comments

Comments
 (0)