dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.38k stars 4.75k forks source link

WCF service with DataContract and EnumValues not returning enum values in result #101594

Closed nealculiner closed 4 months ago

nealculiner commented 6 months ago

Description

I'm in the process of migrating a Xamarin.iOS app to net8.0-ios. I'm finding that some WCF service methods are broken which seem to be related to the wrong serializer being used from what I can tell. I'm using Visual Studio 2022 17.9.6 which is the latest as of this writing. It's a basic WCF service call to a service I host which returns a DataContract with an array of a class which contains an Enum. The enum is decorated with DataContract and each Enum value is decorated with EnumValue and there is an assignment for the 0 value. No matter what I try the enum value is always 0 in the returned array containing a list of this enum object. There are no DataSets in the return value as I've read there is an issue in net8-ios with using the Xml serializer instead of the DataContract serializer. Does anyone have any tips to resolve this as it seems WCF is broken in net8.0-ios.

Steps to Reproduce

Basic WCF service with a class marked with DataContract and enum values marked with EnumValue. I return a List of a class that contains this enum as one of the properties. The enum always comes across as 0.

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

17

Did you find any workaround?

No response

Relevant log output

No response

vitek-karas commented 6 months ago

Does it work in Debug build? Or it's always broken?

nealculiner commented 6 months ago

I'm only using debug build as I do the migration from Xamarin.iOS.

nealculiner commented 6 months ago

Here is the class of which an array of is returned from the WCF service method:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Subscription", Namespace="http://schemas.datacontract.org/2004/07/AppServices.DataContracts")]
public partial class Subscription : object
{

    private System.DateTime ExpirationUtcField;

    private bool IsUserAuthenticatedField;

    private string LinkField;

    private NCSoftware.Utilities.SubscriptionPlan PlanField;

    private string TitleField;

    private string[] UserRolesField;

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public System.DateTime ExpirationUtc
    {
        get
        {
            return this.ExpirationUtcField;
        }
        set
        {
            this.ExpirationUtcField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public bool IsUserAuthenticated
    {
        get
        {
            return this.IsUserAuthenticatedField;
        }
        set
        {
            this.IsUserAuthenticatedField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public string Link
    {
        get
        {
            return this.LinkField;
        }
        set
        {
            this.LinkField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public NCSoftware.Utilities.SubscriptionPlan Plan
    {
        get
        {
            return this.PlanField;
        }
        set
        {
            this.PlanField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public string Title
    {
        get
        {
            return this.TitleField;
        }
        set
        {
            this.TitleField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public string[] UserRoles
    {
        get
        {
            return this.UserRolesField;
        }
        set
        {
            this.UserRolesField = value;
        }
    }
}

This is the enum within the above:


namespace NCSoftware.Utilities
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="SubscriptionPlan", Namespace="http://schemas.datacontract.org/2004/07/NCSoftware.Utilities")]
    public enum SubscriptionPlan : int
    {

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Beta = -2,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        All = -1,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        None = 0,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        ScheduleImporter = 1,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        CloudSync = 2,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        CloudBackup = 3,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Combo = 4,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        CloudDataShared = 5,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        CloudDataPrivate = 6,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        LogbookProMobile = 7,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        APDLMobileBasic = 8,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        APDLMobilePro = 9,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        APDLMobilePrem = 10,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        APDLMobileEnterprise = 11,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        ScheduleImporterNoAPDL = 12,
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="Collation", Namespace="http://schemas.datacontract.org/2004/07/NCSoftware.Utilities")]
    public enum Collation : int
    {

        [System.Runtime.Serialization.EnumMemberAttribute()]
        ByLeg = 0,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        ByDay = 1,
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="TimeZoneModes", Namespace="http://schemas.datacontract.org/2004/07/NCSoftware.Utilities")]
    public enum TimeZoneModes : int
    {

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Local = 0,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        UTC = 1,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        UserDefined = 2,
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="WeatherRadarImageSize", Namespace="http://schemas.datacontract.org/2004/07/NCSoftware.Utilities")]
    public enum WeatherRadarImageSize : int
    {

        [System.Runtime.Serialization.EnumMemberAttribute()]
        SizeAll = -1,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        SizeRaw = 0,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Size680x320 = 1,

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Size1360x640 = 2,
    }
}
drasticactions commented 6 months ago

Can you try running this in a .NET iOS app that doesn't use the MAUI UI Framework? You can do that by installing the iOS workload (dotnet workload install ios) and running dotnet new ios.

IMO This is highly likely to be a dotnet runtime issue and not related to the MAUI UI framework. I would be shocked if something specific within this repo would cause that. @rolfbjarne what do you think?

rolfbjarne commented 6 months ago

IMO This is highly likely to be a dotnet runtime issue and not related to the MAUI UI framework. I would be shocked if something specific within this repo would cause that. @rolfbjarne what do you think?

Agreed, my guess would be either a serializer bug or something with the trimmer. In either case, it's a runtime issue.

nealculiner commented 6 months ago

This is a net8.0-ios app, not maui, but I figured this was the place to log it as they seem to be almost one in the same now but only for ios in my case. I agree, it's probably runtime, if you want to move it, please do. I couldn't figure out where best to report this. Thank you.

drasticactions commented 6 months ago

This is a net8.0-ios app, not maui, but I figured this was the place to log it as they seem to be almost one in the same now but only for ios in my case. I agree, it's probably runtime, if you want to move it, please do. I couldn't figure out where best to report this. Thank you.

No worries, it's easy to confuse and it's easy to move to the right place (unless you're me, I don't have access ;-)) . This repo is for the cross-platform MAUI UI project, so issues like yours get filed here (since most people using the underlying SDK bindings and runtime are doing it through a framework like MAUI) so they hit runtime bugs and file it here since they assume it's one and the same.

For runtime issues, it should go to dotnet/runtime. Specific SDK issues go to xamarin-android and xamarin-macios.

@rolfbjarne (or anyone with access to move it) could you please move this to runtime? Thanks!

dotnet-policy-service[bot] commented 6 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

agocke commented 4 months ago

Without custom steps, XML Serializer isn't trim safe. If this is supposed to work in xamarin-ios then there is a bug in the custom steps. Otherwise, XMLSerializer is marked RUC so this is not expected to work through trimming.

agocke commented 4 months ago

Looks like I can't move issues cross-org, so I'm going to close this and link from a new issue.