Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b9cdf9c

Browse files
committed
don't try create instnce of abstract type
1 parent 8797917 commit b9cdf9c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/ServiceStack.Text/AutoMappingUtils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ public static object CreateDefaultValue(Type type, Dictionary<Type, int> recursi
475475
#endif
476476
}
477477

478+
if (type.IsAbstract())
479+
return null;
480+
478481
// If we have hit our recursion limit for this type, then return null
479482
int recurseLevel; // will get set to 0 if TryGetValue() fails
480483
recursionInfo.TryGetValue(type, out recurseLevel);

tests/ServiceStack.Text.Tests/AutoMappingTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Linq.Expressions;
56
using System.Runtime.Serialization;
@@ -8,6 +9,7 @@
89
#endif
910
using NUnit.Framework;
1011
using ServiceStack.Text.Tests.DynamicModels;
12+
using ServiceStack.Web;
1113

1214
namespace ServiceStack.Text.Tests
1315
{
@@ -692,5 +694,19 @@ public void Can_call_object_setter_Expressions()
692694
fn(test, "Foo");
693695
Assert.That(test.Name, Is.EqualTo("Foo"));
694696
}
697+
698+
public class RawRequest : IRequiresRequestStream
699+
{
700+
public Stream RequestStream { get; set; }
701+
}
702+
703+
[Test]
704+
public void Can_create_DTO_with_Stream()
705+
{
706+
var o = typeof(RawRequest).CreateInstance();
707+
var requestObj = AutoMappingUtils.PopulateWith(o);
708+
709+
Assert.That(requestObj, Is.Not.Null);
710+
}
695711
}
696712
}

0 commit comments

Comments
 (0)