-2

I know this may be silly question. But to be formal I want to store these Class field into list. I tried multiple times but still same things I am facing. I already spend couple of days' to fix this error but unsuccess Please help me on same I want to call web service and bind with drop down list. (Company, Country, Division, Location) which are there in class. But while storing in List I am not able to do that. Its thronging error for obvious region (return type not matching) Error:

(Can not implicitly convert type Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] to Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST[])

I understand due to return type its error appearing but how to store please guide me

I tried like:

[WebMethod]
        public static List<Devision> GetAllFields()
        {
            string userID= "1000";
            GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
            Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST[] divisionMList = oClient.GetInitiatorsList(userID); 

            List<Devision> Division = new List<Devision>();
            foreach (Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST Devision in divisionMList)
            {
                Division.Add(new Devision()
                {
                    DevisionCode = Devision.DivisionCode,
                    DevisionName = Devision.DivisionName
                });
            }
            return Division;
        }

My class Inherit with object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged

I am not pretty sure about this type of object. Can any one Store these class into list

Class:

[System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="INITIATORS_LIST", Namespace="http://schemas.datacontract.org/2004/07/Almarai.Web.Services.DataEntities")]
    [System.SerializableAttribute()]
    public partial class INITIATORS_LIST : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
        
        [System.NonSerializedAttribute()]
        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] CompaniesField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] CountriesField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] DivisionsField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.LOCATION[] LocationsField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.REGION[] RegionsField;
        
        [System.Runtime.Serialization.OptionalFieldAttribute()]
        private Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypesField;
        
        [global::System.ComponentModel.BrowsableAttribute(false)]
        public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
            get {
                return this.extensionDataField;
            }
            set {
                this.extensionDataField = value;
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] Companies {
            get {
                return this.CompaniesField;
            }
            set {
                if ((object.ReferenceEquals(this.CompaniesField, value) != true)) {
                    this.CompaniesField = value;
                    this.RaisePropertyChanged("Companies");
                }
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] Countries {
            get {
                return this.CountriesField;
            }
            set {
                if ((object.ReferenceEquals(this.CountriesField, value) != true)) {
                    this.CountriesField = value;
                    this.RaisePropertyChanged("Countries");
                }
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] Divisions {
            get {
                return this.DivisionsField;
            }
            set {
                if ((object.ReferenceEquals(this.DivisionsField, value) != true)) {
                    this.DivisionsField = value;
                    this.RaisePropertyChanged("Divisions");
                }
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.LOCATION[] Locations {
            get {
                return this.LocationsField;
            }
            set {
                if ((object.ReferenceEquals(this.LocationsField, value) != true)) {
                    this.LocationsField = value;
                    this.RaisePropertyChanged("Locations");
                }
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.REGION[] Regions {
            get {
                return this.RegionsField;
            }
            set {
                if ((object.ReferenceEquals(this.RegionsField, value) != true)) {
                    this.RegionsField = value;
                    this.RaisePropertyChanged("Regions");
                }
            }
        }
        
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypes {
            get {
                return this.WorkflowTypesField;
            }
            set {
                if ((object.ReferenceEquals(this.WorkflowTypesField, value) != true)) {
                    this.WorkflowTypesField = value;
                    this.RaisePropertyChanged("WorkflowTypes");
                }
            }
        }
        
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        
        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

INITIATOR_LIST Class:

[System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="INITIATORS_LIST", Namespace="http://schemas.datacontract.org/2004/07/Almarai.Web.Services.DataEntities")]
            [System.SerializableAttribute()]
            public partial class INITIATORS_LIST : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
                
                [System.NonSerializedAttribute()]
                private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] CompaniesField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] CountriesField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] DivisionsField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.LOCATION[] LocationsField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.REGION[] RegionsField;
                
                [System.Runtime.Serialization.OptionalFieldAttribute()]
                private Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypesField;
                
                [global::System.ComponentModel.BrowsableAttribute(false)]
                public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
                    get {
                        return this.extensionDataField;
                    }
                    set {
                        this.extensionDataField = value;
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] Companies {
                    get {
                        return this.CompaniesField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.CompaniesField, value) != true)) {
                            this.CompaniesField = value;
                            this.RaisePropertyChanged("Companies");
                        }
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] Countries {
                    get {
                        return this.CountriesField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.CountriesField, value) != true)) {
                            this.CountriesField = value;
                            this.RaisePropertyChanged("Countries");
                        }
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] Divisions {
                    get {
                        return this.DivisionsField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.DivisionsField, value) != true)) {
                            this.DivisionsField = value;
                            this.RaisePropertyChanged("Divisions");
                        }
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.LOCATION[] Locations {
                    get {
                        return this.LocationsField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.LocationsField, value) != true)) {
                            this.LocationsField = value;
                            this.RaisePropertyChanged("Locations");
                        }
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.REGION[] Regions {
                    get {
                        return this.RegionsField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.RegionsField, value) != true)) {
                            this.RegionsField = value;
                            this.RaisePropertyChanged("Regions");
                        }
                    }
                }
                
                [System.Runtime.Serialization.DataMemberAttribute()]
                public Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypes {
                    get {
                        return this.WorkflowTypesField;
                    }
                    set {
                        if ((object.ReferenceEquals(this.WorkflowTypesField, value) != true)) {
                            this.WorkflowTypesField = value;
                            this.RaisePropertyChanged("WorkflowTypes");
                        }
                    }
                }
                
                public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
                
                protected void RaisePropertyChanged(string propertyName) {
                    System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
                    if ((propertyChanged != null)) {
                        propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
                    }
                }
            }
Nits Patel
  • 380
  • 3
  • 15
  • On what line exactly are you getting the error? – Frank Nielsen Sep 30 '20 at 19:25
  • @FrankNielsen I am getting error on Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST[] divisionMList = oClient.GetInitiatorsList(userID); saying can not implicitly covert – Nits Patel Sep 30 '20 at 19:50
  • ok, the error message says that `oClient.GetInitiatorsList(userID)` returns a different format that you code expect. Are you sure that your `class INITIATORS_LIST` is the same version as `oClient.GetInitiatorsList(userID)` returns? – Frank Nielsen Sep 30 '20 at 19:58
  • @FrankNielsen yes may I post 'INITIATORS_LIST' class in my code ? Please check I have posted INITIATOR_LIST class in my updated code – Nits Patel Sep 30 '20 at 19:59
  • But `INITIATORS_LIST ` class is a (auto)generate class - right? Try refresh/regenerate the class and see if the properties change. – Frank Nielsen Sep 30 '20 at 20:08
  • Yes all are auto generated class only @FrankNielsen I tried multiples time create another project but not able to add in List it just because due to return type its mismatch I don't understand how to store these kind of data into list – Nits Patel Sep 30 '20 at 20:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222326/discussion-between-frank-nielsen-and-nits-patel). – Frank Nielsen Sep 30 '20 at 20:19

1 Answers1

0

You mixed up the return type of oClient.GetInitiatorsList(userID), it returns ALM_WKFLW_TYPE_M[] and not INITIATORS_LIST[].

So you WebMethod should look like this:

[WebMethod]
        public static List<Devision> GetAllFields()
        {
            string userID= "1000";
            GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
            var almWkflwTypeMList = oClient.GetInitiatorsList(userID); 

            List<Devision> Division = new List<Devision>();
            foreach (var almWkflwTypeM in almWkflwTypeMList)
            {
                Division.Add(new Devision()
                {
                    DevisionCode = almWkflwTypeM.DivisionCode,
                    DevisionName = almWkflwTypeM.DivisionName
                });
            }
            return Division;
        }
Frank Nielsen
  • 1,546
  • 1
  • 10
  • 17
  • I tried in a similar way but I only able to access DivisionField and Workflow field I am looking for Country, Company, Location, Division these fields – Nits Patel Sep 30 '20 at 20:39
  • but they are not part of the result of `oClient.GetInitiatorsList(userID)` as i can see it? Then you have to clas another method on `oClient`. – Frank Nielsen Sep 30 '20 at 20:49
  • It is present in GetInitiatorsListByWorkflow but not able to in foreach loop – Nits Patel Sep 30 '20 at 21:06
  • See this is available in INTIATORLIST as you can see structure of that : INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode); – Nits Patel Sep 30 '20 at 21:07
  • well, it is a bit hard for me to help you further - since i dont known the api and the domain model. But try `GetInitiatorsListByWorkflow` when you have found the correct WorkflowTypeCode to use. – Frank Nielsen Sep 30 '20 at 21:11
  • Now on foreach loop its showing : foreach statement can not operate on variable of type 'INITIATOR_LIST' Because 'INITIATOR_LIST' does not contain a public instance definition for 'GetEnumerator' – Nits Patel Sep 30 '20 at 21:12
  • I have WorkflowTypeCode value even though I can pass WorkflowTypeCode value and able to see JSON data May it helps please – Nits Patel Sep 30 '20 at 21:13
  • Check the return type, it is properly returning a single instance and not an array. – Frank Nielsen Sep 30 '20 at 21:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222328/discussion-between-nits-patel-and-frank-nielsen). – Nits Patel Sep 30 '20 at 21:29