diff --git a/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
index 373a779..aff4002 100644
--- a/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
+++ b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
@@ -26,6 +26,19 @@ public static function buildProxyClassName($class_name) {
   }
 
   /**
+   * Generates the used class-loading function name from a given class name.
+   *
+   * @param $class_name
+   *   The class name of the actual service.
+   *
+   * @return string
+   *   The function name for loading the proxy class.
+   */
+  public static function buildProxyLoadFunctionName($class_name) {
+    return 'drupal_load_proxy__' . self::buildProxyClassName($class_name);
+  }
+
+  /**
    * Builds a proxy class string.
    *
    * @param string $class_name
@@ -128,6 +141,13 @@ public function build($class_name) {
 
     $final_output = $class_documentation . $class_start . "\n{\n\n" . $output . "\n}\n";
 
+    // Wrap class definition into a loading function, so we don't get exceptions
+    // for missing interfaces when the dumped container is loaded. When the
+    // class is instantiated, module namespaces will have been registered and
+    // the respective interfaces will be available via the class auto loader.
+    $final_output = "function {{ load_function_name }}() { \n" . $final_output . "\n}";
+
+    $final_output = str_replace('{{ load_function_name }}', $this->buildProxyLoadFunctionName($class_name), $final_output);
     $final_output = str_replace('{{ class_name }}', $class_name, $final_output);
     $final_output = str_replace('{{ proxy_class_name }}', $this->buildProxyClassName($class_name), $final_output);
 
diff --git a/core/lib/Drupal/Component/ProxyBuilder/ProxyDumper.php b/core/lib/Drupal/Component/ProxyBuilder/ProxyDumper.php
index 7126062..cdc6e1a 100644
--- a/core/lib/Drupal/Component/ProxyBuilder/ProxyDumper.php
+++ b/core/lib/Drupal/Component/ProxyBuilder/ProxyDumper.php
@@ -49,11 +49,13 @@ public function getProxyFactoryCode(Definition $definition, $id) {
     // ProxyBuilder calls the method with lazy loading disabled.
     $output = <<<'EOS'
         if ($lazyLoad) {
+            {{ load_function_name }}();
             return $this->services['{{ id }}'] = new {{ class_name }}($this, '{{ id }}');
         }
 
 EOS;
     $output = str_replace('{{ id }}', $id, $output);
+    $output = str_replace('{{ load_function_name }}', $this->builder->buildProxyLoadFunctionName($definition->getClass()), $output);
     $output = str_replace('{{ class_name }}', $this->builder->buildProxyClassName($definition->getClass()), $output);
 
     return $output;
diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml
index df4d0d7..2a789af 100644
--- a/core/modules/block/block.services.yml
+++ b/core/modules/block/block.services.yml
@@ -25,3 +25,4 @@ services:
   block.repository:
     class: Drupal\block\BlockRepository
     arguments: ['@entity.manager', '@theme.manager', '@context.handler']
+    lazy: true
