Fatal Error HtmlRouteProvider not found? Fatal Error: Fatal error: Class
  'Drupal\custom_avatar\CustomAvatarHtmlRouteProvider' not found in
  /Sites/drupal8/core/lib/Drupal/Core/Entity/EntityTypeManager.php on
  line 252


I am creating config Entity type and below is structure of my module shown in screenshot: 



I below code I have defined below routing so that I don't have to define each of these routes statically in our module's routing.yml file. My class extends AdminHtmlRouteProvider :


  "route_provider" = {
         "html" = "Drupal\custom_avatar\CustomAvatarHtmlRouteProvider",
       },


&lt;?php

namespace Drupal\custom_avatar\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;


/**
 * Defines the Avatar profile entity.
 *
 * @ConfigEntityType(
 *   id = "custom_avatar",
 *   label = @Translation("Avatars for user profiles"),
 *   handlers = {
 *     "list_builder" = "Drupal\custom_avatar\CustomAvatarListBuilder",
 *     "form" = {
 *       "add" = "Drupal\custom_avatar\Form\CustomAvatarForm",
 *       "edit" = "Drupal\custom_avatar\Form\CustomAvatarForm",
 *       "delete" = "Drupal\custom_avatar\Form\CustomAvatarFormDeleteForm"
 *     },
 *     "route_provider" = {
 *       "html" = "Drupal\custom_avatar\CustomAvatarHtmlRouteProvider",
 *     },
 *   },
 *   config_prefix = "custom_avatar",
 *   admin_permission = "administer site configuration",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid"
 *   },
 *   links = {
 *     "canonical" = "/admin/structure/custom_avatar/{custom_avatar}",
 *     "add-form" = "/admin/structure/custom_avatar/add",
 *     "edit-form" = "/admin/structure/custom_avatar/{custom_avatar}/edit",
 *     "delete-form" = "/admin/structure/custom_avatar/{custom_avatar}/delete",
 *     "collection" = "/admin/structure/custom_avatar"
 *   }
 * )
 */

class CustomAvatar extends ConfigEntityBase implements CustomAvatarInterface {
  /**
   * The Avatar profile ID.
   *
   * @var string
   */
  protected $id;

  /**
   * The Avatar profile label.
   *
   * @var string
   */
  protected $label;
}




&lt;?php

namespace Drupal\custom_avatar;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;

class CustomAvatarHtmlRouteProvider extends AdminHtmlRouteProvider {

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = parent::getRoutes($entity_type);

    $entity_type_id = $entity_type-&gt;id();

    if ($collection_route = $this-&gt;getCollectionRoute($entity_type)) {
      $collection-&gt;add("entity.{$entity_type_id}.collection", $collection_route);
    }

    return $collection;
  }

  /**
   * Gets the collection route.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getCollectionRoute(EntityTypeInterface $entity_type) {
    if ($entity_type-&gt;hasLinkTemplate('collection') &amp;&amp; $entity_type-&gt;hasListBuilderClass()) {
      $entity_type_id = $entity_type-&gt;id();
      $route = new Route($entity_type-&gt;getLinkTemplate('collection'));
      $route
        -&gt;setDefaults([
          '_entity_list' =&gt; $entity_type_id,
          // Make sure this is not a TranslatableMarkup object as the
          // TitleResolver translates this string again.
          '_title' =&gt; (string) $entity_type-&gt;getLabel(),
        ])
        -&gt;setRequirement('_permission', $entity_type-&gt;getAdminPermission())
        -&gt;setOption('_admin_route', TRUE);

      return $route;
    }
  }

}


Please suggest what is cause of error, the module gets installed without any error but when I clear all cache it shows error and the routs are not build using this way(page not found). I want to try using this class to build dynamic admin (canonical, add, edit, and delete forms for entities ) routs rather than defining in routing.yml 

Thanks!
Unless you’re doing something custom, your classes need to be under ./src to be discovered. By default, MODULE/src/Foo.php is mapped to the Drupal\MODULE\Foo namespace and so on.

Move the two classes out of the root of your module and into ./src, clear cache, and try again.

See PSR4 namespaces and autoloading in Drupal 8 for full details.