Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add try catch to CLR Object Marshaler getStringValue #10952

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
22 changes: 17 additions & 5 deletions test/Engine/FFITarget/ClassFunctionality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class ClassFunctionality : IDisposable
private int intVal;
public int IntVal {
get { return intVal; }
set {
set {
this.intVal = value;
this.classProperty = new ValueContainer(intVal);
}
}

public ClassFunctionality()
{

}

public ClassFunctionality(int intVal)
Expand Down Expand Up @@ -103,8 +103,8 @@ public void Dispose()
{
StaticProp++;
}


}

public class ValueContainer
Expand All @@ -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; }
Expand Down Expand Up @@ -154,4 +154,16 @@ public void Dispose()
{
}
}

public class ClassWithExceptionToString{

public static ClassWithExceptionToString Construct()
{
return new ClassWithExceptionToString();
}
public override string ToString()
{
throw new NotImplementedException();
}
}
}
15 changes: 14 additions & 1 deletion test/Engine/ProtoTest/FFITests/FFITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void T021_Vector_ByCoordinates_1458422_Regress()
thisTest.Verify("vc1Value", 3);
thisTest.Verify("vc2Value", 3);

}
}

[Test]
[Category("SmokeTest")]
Expand Down Expand Up @@ -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); });

}
}
}