Fair question; it isn't a scenario that has come up before, but it is a fair-enough scenario, and is pretty easily solved, thankfully... I've added AutoAddProtoContractTypesOnly
to RuntimeTypeModel
in r567. If you are using the v1-style Serializer.Serialize(...)
methods, then you can apply this via:
RuntimeTypeModel.Default.AutoAddProtoContractTypesOnly = true;
(all the Serializer.*
methods are mapped to the RuntimeTypeModel.Default
model instance)
Here's my now-passing test:
[Test]
public void ExecuteWithoutAutoAddProtoContractTypesOnlyShouldWork()
{
var model = TypeModel.Create();
Assert.IsInstanceOfType(typeof(Foo), model.DeepClone(new Foo()));
}
[Test, ExpectedException(typeof(InvalidOperationException),
ExpectedMessage = "Type is not expected, and no contract can be inferred: Examples.Issues.SO11871726+Foo")]
public void ExecuteWithAutoAddProtoContractTypesOnlyShouldFail()
{
var model = TypeModel.Create();
model.AutoAddProtoContractTypesOnly = true;
Assert.IsInstanceOfType(typeof(Foo), model.DeepClone(new Foo()));
}
[DataContract]
public class Foo { }