From db76896a149f0ee3bbbd06fe53709bd5a02d5ba7 Mon Sep 17 00:00:00 2001 From: mjkkirschner Date: Wed, 29 Jul 2020 14:18:20 -0400 Subject: [PATCH 1/2] add try catch add test --- .../ProtoCore/FFI/CLRObjectMarshaler.cs | 27 ++++++++++++------- test/Engine/ProtoTest/FFITests/FFITest.cs | 15 ++++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs b/src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs index b4af04e947a..37ebf55d6b8 100644 --- a/src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs +++ b/src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs @@ -1256,22 +1256,29 @@ public override string GetStringValue(StackValue dsObject) if (clrObject != null) { - if (!DumpXmlProperties) - { - return clrObject.ToString(); - } - else + try { - XmlWriterSettings settings = new XmlWriterSettings { Indent = false, OmitXmlDeclaration = true }; - using (StringWriter sw = new StringWriter()) + if (!DumpXmlProperties) { - using (XmlWriter xw = XmlTextWriter.Create(sw, settings)) + return clrObject.ToString(); + } + else + { + XmlWriterSettings settings = new XmlWriterSettings { Indent = false, OmitXmlDeclaration = true }; + using (StringWriter sw = new StringWriter()) { - GeneratePrimaryPropertiesAsXml(clrObject, xw); + using (XmlWriter xw = XmlTextWriter.Create(sw, settings)) + { + GeneratePrimaryPropertiesAsXml(clrObject, xw); + } + return sw.ToString(); } - return sw.ToString(); } } + catch + { + return string.Empty; + } } else { diff --git a/test/Engine/ProtoTest/FFITests/FFITest.cs b/test/Engine/ProtoTest/FFITests/FFITest.cs index 610deadbd0c..fdd397bee23 100644 --- a/test/Engine/ProtoTest/FFITests/FFITest.cs +++ b/test/Engine/ProtoTest/FFITests/FFITest.cs @@ -41,7 +41,7 @@ public void T021_Vector_ByCoordinates_1458422_Regress() thisTest.Verify("vc1Value", 3); thisTest.Verify("vc2Value", 3); - } +} [Test] [Category("SmokeTest")] @@ -180,5 +180,18 @@ public void TestDefaultArgumentAttribute() string expression = o as string; Assert.IsTrue(expression.Equals("TestData.GetFloat()")); } + + [Test] + public void TestToStringDoesNotThrow() + { + string code = @" +import (ClassWithExceptionToString from ""FFITarget.dll""); +x = ClassWithExceptionToString.Construct(); +"; + var mirror = thisTest.RunScriptSource(code); + var x = mirror.GetValue("x"); + Assert.DoesNotThrow(() => { mirror.GetStringValue(x,this.core.Heap, 0); }); + + } } } From daff67714dcb6dc7805419f1eaad12136195f686 Mon Sep 17 00:00:00 2001 From: mjkkirschner Date: Wed, 29 Jul 2020 15:40:08 -0400 Subject: [PATCH 2/2] add new class to ffitarget --- test/Engine/FFITarget/ClassFunctionality.cs | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/Engine/FFITarget/ClassFunctionality.cs b/test/Engine/FFITarget/ClassFunctionality.cs index c5562ed50b1..d2ec1805110 100644 --- a/test/Engine/FFITarget/ClassFunctionality.cs +++ b/test/Engine/FFITarget/ClassFunctionality.cs @@ -11,7 +11,7 @@ public class ClassFunctionality : IDisposable private int intVal; public int IntVal { get { return intVal; } - set { + set { this.intVal = value; this.classProperty = new ValueContainer(intVal); } @@ -19,7 +19,7 @@ public int IntVal { public ClassFunctionality() { - + } public ClassFunctionality(int intVal) @@ -103,8 +103,8 @@ public void Dispose() { StaticProp++; } - - + + } public class ValueContainer @@ -116,7 +116,7 @@ public ValueContainer(int value) public ValueContainer Square() { - return new ValueContainer(SomeValue * SomeValue); + return new ValueContainer(SomeValue * SomeValue); } public int SomeValue { get; set; } @@ -154,4 +154,16 @@ public void Dispose() { } } + + public class ClassWithExceptionToString{ + + public static ClassWithExceptionToString Construct() + { + return new ClassWithExceptionToString(); + } + public override string ToString() + { + throw new NotImplementedException(); + } + } }