question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetKnownTypes for dynamic known type list

See original GitHub issue

WCF in .Net framework had an overload for ServiceKnownType as follows:

[ServiceKnownType("GetKnownTypes", typeof(DataProviderTypes))]
public interface IService
{
}

public class DataProviderTypes
{
    public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
    {
        List<Type> lst = new List<Type>();
        '
        '
        return lst;
    }
}

This allowed to dynamically generate list of known types.

Is there any way to achieve this ? If not, when is this planned ? Coz this is looking like a showstopper.

Thanks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mconnewcommented, Dec 9, 2021

Yes, a new ServiceKnownTypeTests.cs can be created. Feel free to open a draft PR so that you can get some feedback before you are complete if you would like. I’m happy with reducing the usage of CustomAttributeProvider and relegating it to only being used to get custom attributes including the converting System.ServiceModel variations to CoreWCF ones. I think we could get away with turning it into a static class and making the method an extension method on ICustomAttributeProvider. Probably need to rename it otherwise the ICustomAttributeProvider version of the method would get called instead. I’m open to any cleanup you would like to do, or you can make the minimal changes required. It’s up to you.

1reaction
mconnewcommented, Dec 2, 2021

That comment is a holdover from very early .NET Standard days when that interface wasn’t available. It wasn’t the reason why that overload wasn’t supported though. It was because this code was originally ported for UWP apps running on .NET Native which didn’t allow reflection and dynamically calling of methods. This can definitely be re-enable. I’ll take a look later to see how much work this will be.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you configure WCF known types programmatically?
In the GetKnownTypes method, which is just code, you can return the known types at that point in time. The attribute is just...
Read more >
Data Contract Known Types - WCF
Learn how the data contract model uses the KnownTypeAttribute class to specify the types to include during deserialization in WCF.
Read more >
add known types to wcf service dynamically
After some experiences I camed out to the following code. It takes care of finding the missing types used in an operation contract....
Read more >
Writing Highly Maintainable WCF Services
Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the ......
Read more >
Part 7 KnownType attribute in WCF - YouTube
... inherited types, then use KnownType attribute. There are other ways of associating known types, which we will discuss in next video session....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found