diff --git a/core/lib/Drupal/Core/DependencyInjection/Container.php b/core/lib/Drupal/Core/DependencyInjection/Container.php
index 1869bfc..42bf890 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Container.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Container.php
@@ -27,4 +27,12 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
     return $service;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  function __sleep() {
+    trigger_error('The container was serialized.', E_USER_ERROR);
+    return array_keys(get_object_vars($this));
+  }
+
 }
diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index 736680d..adda4a3 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -29,6 +29,19 @@ public function addObjectResource($object) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) {
+    $service = parent::get($id, $invalidBehavior);
+    // Some services are called but do not exist, so the parent returns nothing.
+    if (is_object($service)) {
+      $service->_serviceId = $id;
+    }
+
+    return $service;
+  }
+
+  /**
    * Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().
    *
    * Drupal's container builder can be used at runtime after compilation, so we
@@ -89,4 +102,12 @@ protected function callMethod($service, $call) {
     call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  function __sleep() {
+    trigger_error('The container was serialized.', E_USER_ERROR);
+    return array_keys(get_object_vars($this));
+  }
+
 }
