dpkg Assertion 'dependtry <= 4' failed

If you happen to come across the following error while using dpkg (or apt-get):

dpkg: ../../src/packages.c:191: process_queue: Assertion `dependtry <= 4' failed
E: Sub-process /usr/bin/dpkg exited unexpectedly

The solution is as simple as:

# dpkg --configure -a --force-depends

According to Antti-Juhani Kaijanaho:

There are two known triggers for that bug:

  • A package depends on itself. (This is a bug in the package.)

  • There is a dependency loop which involves a virtual package. (This would be valid use of the dependency fields, if this bug did not exist.)