Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong Return Type

Tags:

c#

return-type

I don't understand why I am getting an error of:

'System.Collections.Generic.List Notify.MainPage.webClient_OpenReadCompleted(object, System.Net.OpenReadCompletedEventArgs)' has the wrong return type

Code:

webClient.OpenReadCompleted += webClient_OpenReadCompleted;

And:

private List<SightingType> webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            DataContractJsonSerializer ser = null;
            var sightingT = new List<SightingType>();
            try
            {
                ser = new DataContractJsonSerializer(typeof(ObservableCollection<SightingType>));
                ObservableCollection<SightingType> sightingTypes = ser.ReadObject(e.Result) as ObservableCollection<SightingType>;
                foreach (var sightingType in sightingTypes)
                {
                    sightingT.Add(sightingType);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return sightingT;
        }

Does anyone know where I am going wrong?

like image 759
Subby Avatar asked Mar 19 '26 10:03

Subby


1 Answers

The return type of an event handler should be void:

private void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {

There's nothing at the other end to receive the return data.

like image 169
Keith Payne Avatar answered Mar 20 '26 23:03

Keith Payne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!