title: Symfony4 Error loading classes custom folder "Expected to find class... but it was not found"
body: <h2>Problem</h2>
  
  <p>I'm trying to setup a custom directory structure 
  for some shared classes in my Symfony project. I
  want to create a custom folder in the root of my
  project and I want to use the Symfony auto-load 
  feature to automatically register services from 
  that folder.</p>
  
  <p>So I added a custom services namespace to the
  services.yaml file:</p>
  
  <pre><code># src ./config/services.yaml
  services:
      ...
  
      TestNamespace\:
      resource: '../TestNamespace/*'
  
    ...
  </code></pre>
  
  <p>And I added an empty class in the custom folder:</p>
  
  <pre><code># src ./TestNamespace/TestClass.php
  
  namespace TestNamespace;
  
  class TestClass
  {
  
  }
  </code></pre>
  
  <p>When I run the app I get the following error:</p>
  
  <pre><code>(1/2) InvalidArgumentException
  Expected to find class "TestNamespace\TestClass" in file 
  "/path/to/ClassLoadErrorDemo/demo/TestNamespace/TestClass.php"
  while importing services from resource 
  "../TestNamespace/*", but it was not found! Check the
  namespace prefix used with the resource.
  
  (2/2) FileLoaderLoadException
  Expected to find class "TestNamespace\TestClass" in file 
  "/path/to/ClassLoadErrorDemo/demo/TestNamespace/TestClass.php" while 
  importing services from resource "../TestNamespace/*", but it was not 
  found! Check the namespace prefix used with the resource in 
  /path/to/ClassLoadErrorDemo/demo/config/services.yaml (which is loaded 
  in resource "/path/to/ClassLoadErrorDemo/demo/config/services.yaml").
  </code></pre>
  
  <p>I double checked the paths, namespace and the class 
  name multiple times and everything seems fine and I 
  don't understand why I still get the error.
  Controllers in the ./src folder seem to load fine.
  What am I doing wrong here? </p>
  
  <h2>Steps to reproduce</h2>
  
  <p>I created a demo repo to isolate the problem.</p>
  
  <pre><code>git clone https://github.com/smoelker/SymfonyClassLoadErrorDemo.git
  cd SymfonyClassLoadErrorDemo/demo
  composer install
  mv TestNamespace/TestClass.php_ TestNamespace/TestClass.php
  php bin/console server:start
  </code></pre>