locked
WCF throws exception when trying to return class with IDictionary properties RRS feed

  • Question

  • Hi!

    I have a class which returns a combination of properties based on primitive types and properties based on IDictionary. When I comment the IDic-properties out I'm able to publish it through a WCF ServiceOperation. However, when I re-enable them I get an exception. For various reasons I need to keep this IDic-approach. Is there a possible workaround to this?

    BTW - I'm using WCF 4.

    Thanks!
    /Peter

    Tuesday, November 2, 2010 7:57 PM

Answers

  • Hi,

    I assume you're using WCF Data Services (as it's not clear from your question).

    WCF Data Services in .NET 4.0 doesn't support properties of type Dictionary/IDictionary. If you want to use the dictionary as a property bag (you want to expose properties from the key/value pairs in it) then you would need to implement a custom provider. Are you doing that? Or are you using a simple reflection provider? (simple way to tell is if you implemented an IDataServiceMetadataProvider interface).

    Is the list of properties on each entity type static (so the dictionary is just a storage), or does it change instance from instance? If it's the latter then you would need to use so called open types/properties, which are also only supported in custom provider.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by The Way Wednesday, November 3, 2010 7:18 AM
    Wednesday, November 3, 2010 7:05 AM
    Moderator