How do I fix a ReflectionException error (class doesn't exist)? I'm new to drupal 8. I would like to extend the user login form by deleting the username field and adding the email field. So I created a custom module, I implemented an Event Subscriber and declared it as a service :

services:
    mdmuser.route_subscriber:
        class: Drupal\mdm_user\Routing\RouteSubscriber
        tags: 
             - {name: event_subscriber }


And here's my class RouteSubscriber

 &lt;?php

 /**
 * @file
 * Contains \Drupal\mdm_user\Routing\RouteSubscriber.
 */

 namespace Drupal\mdm_user\Routing;

 use Drupal\Core\Routing\RouteSubscriberBase;
 use Symfony\Component\Routing\RouteCollection;

 /**
 * Listens to the dynamic route events.
 */
 class RouteSubscriber extends RouteSubscriberBase {

 protected function alterRoutes(RouteCollection $collection) {

     if ($route = $collection-&gt;get('user.login')) {
      $route-&gt;setDefault('_form', '\Drupal\mdm_user\Form\UserLoginForm');
      $collection-&gt;add('user.login', $route);
    }
  }
}


I have this error when I want to install my new module :

ReflectionException: Class Drupal\mdm_user\Routing\RouteSubscriber does not exist in ReflectionClass-&gt;__construct() (line 31 of core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php).


Any idea is appreciated !

Thanks
It has to be the file structure.  Check again that it's at /modules/custom/mdm_user/src/Routing/RouteSubscriber.php

Also, in your class, you don't need to add the route again, it's passed by reference.

You can remove 

$collection-&gt;add('user.login', $route);