Skip to content

Commit

Permalink
Merge pull request microsoft#90 from saikrishnav/stackoverflowfixport
Browse files Browse the repository at this point in the history
StackOverflowFix Port: Merge pull request microsoft#89 from saikrishnav/stackoverflowfix
  • Loading branch information
Sai Krishna V authored Sep 27, 2016
2 parents cf65531 + b4bee6a commit 4034866
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Microsoft.TestPlatform.ObjectModel/TestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel
[DataContract]
public abstract class TestObject
{
static TestObject()
{
// Do TypeConverter registrations in static constructor only to avoid multiple registrations
// If we register too much, deserialization of large number of testobjects will cause StackOverflow exception
TypeDescriptor.AddAttributes(typeof(Guid), new TypeConverterAttribute(typeof(CustomGuidConverter)));
TypeDescriptor.AddAttributes(typeof(KeyValuePair<string, string>[]), new TypeConverterAttribute(typeof(CustomKeyValueConverter)));
TypeDescriptor.AddAttributes(typeof(string[]), new TypeConverterAttribute(typeof(CustomStringArrayConverter)));
}

#region Fields

/// <summary>
Expand Down Expand Up @@ -64,9 +73,6 @@ private List<KeyValuePair<TestProperty, object>> StoreKeyValuePairs
protected TestObject()
{
this.store = new Dictionary<TestProperty, object>();
TypeDescriptor.AddAttributes(typeof(Guid), new TypeConverterAttribute(typeof(CustomGuidConverter)));
TypeDescriptor.AddAttributes(typeof(KeyValuePair<string, string>[]), new TypeConverterAttribute(typeof(CustomKeyValueConverter)));
TypeDescriptor.AddAttributes(typeof(string[]), new TypeConverterAttribute(typeof(CustomStringArrayConverter)));
}

[OnSerializing]
Expand Down

0 comments on commit 4034866

Please sign in to comment.