RobotStudio event

EventLog.MessageWritten object reference not set to an instance of an object exception

Hello, I would like to know why when I try to create an event handler for MessageWritten in some controllers I get the message object reference not set to an instance of an object exception. The source code in C# and the stacker trace are down below:

scanner = new NetworkScanner();
            scanner.Scan();
            controllers = scanner.GetControllers();
            ListViewItem item = null;

            foreach (ControllerInfo controllerInfo in controllers)
            {
                // Add the controllers which are detected to the ListView
                item = new ListViewItem(controllerInfo.IPAddress.ToString());
                item.SubItems.Add(controllerInfo.Id);
                item.SubItems.Add(controllerInfo.Availability.ToString());
                item.SubItems.Add(controllerInfo.IsVirtual.ToString());
                item.SubItems.Add(controllerInfo.SystemName);
                item.SubItems.Add(controllerInfo.Version.ToString());
                item.SubItems.Add(controllerInfo.ControllerName);
                listView1.Items.Add(item);
                item.Tag = controllerInfo;

                // Create an object controller foreach robot in the network and activate the event handler to log the Event Messages.
                Controller controller = new Controller(controllerInfo);

                try
                {
                    controller.EventLog.MessageWritten += (sender, e) => log_MessageWritten(sender, e, controller);
                }
                catch (Exception e)
                {
                }

Stacker trace:
at ABB.Robotics.Controllers.EventLogDomain.EventLog.GetCategory(Int32 id)
at ABB.Robotics.Controllers.EventLogDomain.EventLog.Subscribe(EventHandler`1 handler)
at ABB.Robotics.Controllers.EventLogDomain.EventLog.add_MessageWritten(EventHandler`1 value) 

I have tried the code in controllers version 6.03.00 ; 6.05.00 ; 6.04.01 ; 6.06.00 and the interesting thing is that the version does not matter because I have tested in different controllers with the same version and sometimes I got the exception sometimes not. That makes me wonder what is causing that in some controllers I have the exception and others not...