Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:39:45+00:00 2026-06-10T22:39:45+00:00

I have a service contract interface that looks like this: [ServiceKnownType(typeof(GeometricModelDescriptor))] [ServiceKnownType(typeof(TemplateModelDescriptor))] [ServiceContract] public

  • 0

I have a service contract interface that looks like this:

[ServiceKnownType(typeof(GeometricModelDescriptor))]
[ServiceKnownType(typeof(TemplateModelDescriptor))]
[ServiceContract]
public interface IModelRepository
{
    [OperationContract]
    ModelDescriptor GetDescriptor(ModelHandle model);
}

It uses some simple data-contract types like this:

[DataContract]
public class ModelDescriptor
{
    //...
}

[DataContract]
public sealed class GeometricModelDescriptor : ModelDescriptor
{
    //...
}

When I attempt to call the GetDescriptor method, I get a serialization exception indicating that the client proxy can’t deserialize the type:

Element ‘http://tempuri.org/:GetDescriptorResult‘ contains data from a
type that maps to the name
‘MyNamespace:GeometricModelDescriptor’. The
deserializer has no knowledge of any type that maps to this name.
Consider using a DataContractResolver or add the type corresponding to
‘GeometricModelDescriptor’ to the list of known types – for example,
by using the KnownTypeAttribute attribute or by adding it to the list
of known types passed to DataContractSerializer.

My understanding is that the ServiceKnownType attributes should prevent this exception. What am I missing?


Folks have asked for the client code. It’s a bit involved, but here is the crux of the logic that generates the client proxy wrapper:

                var baseType = typeof(ClientBase<>).MakeGenericType(typeof(TService));
                var proxyType = _module.DefineType("ProxyType" + typeof(TService).Name,
                                                     TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
                                                     baseType,
                                                     new[] { typeof(TService) });
                var constructor = proxyType.DefineConstructor(MethodAttributes.Public,
                                                              CallingConventions.HasThis,
                                                              new[] { typeof(ServiceEndpoint)});
                var il = constructor.GetILGenerator();
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldarg_1);
                il.Emit(OpCodes.Call, baseType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance,
                                                              null,
                                                              new[] {typeof(ServiceEndpoint)},
                                                              null));
                il.Emit(OpCodes.Ret);

                var interfaces = FlattenInterfaces(typeof(TService)).ToList();
                foreach (var interfaceType in interfaces)
                {
                    BuildInterfaceMethods(typeof(TService), proxyType, interfaceType);
                }

This creates a ClientBase<IService> descendent, which also implements IService. The interface implementation (built via BuildInterfaceMethods) routes each method call through the protected Channel property provided by ClientBase. The emitted class is the equivalent of this:

    public sealed class ModelRepositoryProxy : ClientBase<IModelRepository>, IModelRepository
    {
        //Constructor omitted for brevity...
        ModelDescriptor IModelRepository.GetDescriptor(ModelHandle model)
        {
            return Channel.GetDescriptor(model);
        }
    }

I ended up using a solution outlined in this answer, by calling the IDesign AddGenericResolver on the client for each service known type shortly after constructing it. This registers a DataContractSerializerOperationBehavior that knows how to resolve the specified types. It’s not clear to me why this is necessary to allow the client to resolve the types, but it works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:39:47+00:00Added an answer on June 10, 2026 at 10:39 pm

    It looks like you have problem on the client side, not on the server. The problem might be because of you have added ServiceKnownType attributes after you have generated the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service with multiple contracts like so. [ServiceContract] public partial interface IBusinessFunctionDAO
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
I have the following: [ServiceContract] [ServiceKnownType(typeof(ActionParameters))] [ServiceKnownType(typeof(SportProgram))] [ServiceKnownType(typeof(ActionResult<SportProgram>))] public interface ISportProgramBl { [OperationContract] IActionResult<ISportProgram>
I have a very simples Hello World WCF Service, that looks like this: namespace
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
Ok so I have two objects that look like this in my WCF service.
Say I have the following service contract and two concrete implementations: [OperationContract] public interface
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have the following ServiceContract: [ServiceContract(Namespace = http://WebAdmin.Services.AdministrativeService, Name = AdministrativeService)] public interface IAdministrativeService

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.