-1

I am getting the above error : System.AggregateException: One or more errors occurred.

With this line of code here:

    List<tblDeviceIds> installIDs = KumulosHelper.Functions.Device.GetDeviceIDsOfUser(toUser);

The Method "GetDeviceIdsOfUser" looks like this:

    public static List<tblDeviceIds> GetDeviceIDsOfUser(string username)
    {
        IDictionary<string, string> myDict = new Dictionary<string, string>();
        myDict.Add("username", username);
        return KumulosGeneral.getTblDeviceIds("getDeviceIDsOfUser", myDict);
    }

So, there is really nothing fancy going on.

Sometimes, but only on CERTAIN users above error. So even when the user would be "null", which by the way he never is, the list would just return nothing. BUT instead it crashes. This itself is something I didnt quite understand, so what I did was:

        List<tblDeviceIds> installIDs = null;

        try
        {
            installIDs = KumulosHelper.Functions.Device.GetDeviceIDsOfUser(toUser);
        }
        catch
        {
            installIDs = null;
        }

This would be a bullet prove workaround, but yet: It goes into try, it crashes, it never goes into catch, it is dead. Would someone care to explain?

Thanks!

O, maybe this has something todo with doing this on another thread? This is the function that calls all that:

        await Task.Run(() =>
        {
            Intermediate.SendMessageToUser(toUsername, temp);
        });

As you can see, it is inside an async task... but that should not be a problem, right?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
innomotion media
  • 862
  • 11
  • 30

1 Answers1

1

The reason you receive an AggregateException is because the exception is originating from within a Task (that is likely running on a separate thread). To determine the cause, walk the line of InnerException(s).

Regarding the catch not catching, my suggestions would be: Ensure the latest code is being used. Add Tracing instead of relying on breakpoints. And see if the inner exception is thrown from yet another thread (is GetDeviceIDsOfUser also using async?)

See also: Why is .NET exception not caught by try/catch block?

CtC
  • 54
  • 3