vstest icon indicating copy to clipboard operation
vstest copied to clipboard

DataContract Serialization of TestObject

Open aukevin opened this issue 6 years ago • 1 comments

Description

The TestObject has a [DataMember] that does not properly serialize when sent over WCF.

Steps to reproduce

Below I have two classes that I used to demonstrate the issue, running from VS2019, targeting .NET Framework 4.7.2.

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using System;
using System.ServiceModel;

namespace WCFServer
{
    [ServiceContract]
    public interface ITestResultService
    {
        [OperationContract]
        string GetName(TestResult testResult);
    }

    public class TestResultService : ITestResultService
    {
        public string GetName(TestResult testResult)
        {
            return testResult.TestCase.FullyQualifiedName;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(
                typeof(TestResultService),
                new Uri[]{
                    new Uri("http://localhost:8080")
                }))
            {
                host.AddServiceEndpoint(typeof(ITestResultService),
                    new BasicHttpBinding(),
                    "TestResult");

                host.Open();

                Console.WriteLine("Service is available. Press <ENTER> to exit.");
                Console.ReadLine();

                host.Close();
            }
        }
    }
}
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using System;
using System.ServiceModel;

namespace WCFClient
{
    [ServiceContract]
    public interface ITestResultService
    {
        [OperationContract]
        string GetName(TestResult testResult);
    }

    class Program
    {
        static void Main(string[] args)
        {
            ChannelFactory<ITestResultService> httpFactory =
                new ChannelFactory<ITestResultService>(
                    new BasicHttpBinding(),
                    new EndpointAddress(
                        "http://localhost:8080/TestResult"));

            ITestResultService httpProxy = httpFactory.CreateChannel();

            while (true)
            {
                //var property = TestProperty.Register("id", "label", typeof(int), typeof(TestCase));
                var testCase = new TestCase("fullyQualifiedName", new Uri("http://executerUri"), "source");
                //testCase.SetPropertyValue(property, 3);
                var testResult = new TestResult(testCase);
                Console.WriteLine("http: " + httpProxy.GetName(testResult));
                Console.ReadLine();
            }
        }
    }
}

As is, the program shows:

http: fullyQualifiedName

But when the lines registering and setting the TestProperty are uncommented in the client, the TestResult no longer serializes.

Expected behavior

It was expected that the TestResult continued to serialize, especially given that StoreKeyValuePairs is a DataMember.

Actual behavior

Instead, it throws with

System.ServiceModel.FaultException: 'The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.'

And internally complains about serialization.

Diagnostic logs

I did not run vstest.console to reproduce this issue, so there are no diagnostic logs to show.

Environment

This was running on Windows 10 Enterprise, OS build 18363.535. The version of Microsoft.TestPlatform.ObjectModel used is the latest stable release at the time of asking the question: 16.4.0.

aukevin avatar Dec 17 '19 20:12 aukevin

It is also worth noting that in a previous version of the code that used:

Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

There were no issues in TestResult serialization.

aukevin avatar Dec 17 '19 22:12 aukevin