diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
index 36cd99d586db4a189dd2b30f3731bfb61d727610..96679d5f17a9ed22048d3eb95b45d764b8a6551f 100644
--- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
+++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
@@ -446,8 +446,8 @@ private function validate($content, $file)
             throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
         }
 
-        if ($invalid_keys = array_diff_key($content, array('parameters' => 1, 'services' => 1))) {
-            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid keys %s. Services have to be added under "services" and Parameters under "parameters".', $file, $invalid_keys));
+        if ($invalid_keys = array_keys(array_diff_key($content, array('parameters' => 1, 'services' => 1)))) {
+            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid root key(s) "%s". Services have to be added under "services" and Parameters under "parameters".', $file, implode('", "', $invalid_keys)));
         }
 
         return $content;
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
index 54d996bd07b6813143d65fb5da4d832b93e17180..632edb6d989149b5c9c4deeddf55ba997ecdbf88 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
@@ -171,10 +171,16 @@ public function providerTestExceptions() {
       ],
       'YAML must be valid' => [<<<YAML
    do not:
-      do this for the love of Foo Bar!
+      do: this: for the love of Foo Bar!
 YAML,
         'The file "vfs://drupal/modules/example/example.yml" does not contain valid YAML',
       ],
+      'YAML must have expected keys' => [<<<YAML
+      "do not":
+        do: this
+      YAML,
+        'The service file "vfs://drupal/modules/example/example.yml" is not valid: it contains invalid root key(s) "do not". Services have to be added under "services" and Parameters under "parameters".',
+      ],
     ];
   }