If sudo apt --fix-broken install fails with a dpkg message about one package "trying to overwrite" a file that already belongs to another package — commonly a .dll under /usr/lib/mono/gac/ — your system is stuck with two Mono packages that both claim the same file, usually because a removal was interrupted or because Mono packages from two different repositories are installed side by side. The fix is not to reinstall the conflicting package, but to force-purge the broken set of Mono packages, repair dpkg's internal state, and then let apt settle everything cleanly.
Why This Happens
Dpkg does not allow two packages to own the same file path (with a few sanctioned exceptions for cooperating packages). The error in this situation typically looks like this:
dpkg: error processing archive /var/cache/apt/archives/mono-libraries_...deb (--unpack):
trying to overwrite '/usr/lib/mono/gac/Accessibility/.../Accessibility.dll',
which is also in package libmono-accessibility4.0-cil
There are two common root causes:
- Mixed package sources. Mono ships both in Ubuntu's own repositories and in third-party repositories (such as the official Mono project's). If you install Mono from one source and then partially install or upgrade from the other, the two package sets overlap and fight over the same GAC paths.
- Interrupted removal or upgrade. If you ask apt to remove Mono while related packages (runtimes, development libraries, applications that depend on it) are still half-configured, dpkg can end up with packages marked installed that no longer have consistent contents.
A key diagnostic clue is the output of apt policy: if an installed package's version string contains a repository suffix (like 0xamarin2+ubuntu2004b1) but that version no longer appears in any configured repository's version table — only in /var/lib/dpkg/status — you have an orphaned package from a repo you no longer use. That stale package is what collides with the new one apt is trying to unpack.
Note that manually deleting the conflicting file, as many people try first, does not help. Dpkg's error is about package ownership metadata, not the file on disk; dpkg simply refuses the unpack operation before it even checks whether the file exists.
Step 1: Finish Pending Configuration
Before touching individual packages, let dpkg resolve whatever half-finished transactions are pending:
sudo dpkg --configure -a
If this itself errors out on Mono packages, that is expected — continue to the next step.
Step 2: Force-Purge the Broken Mono Packages
Purge the package that owns the conflicting file and its siblings, ignoring dependency complaints for now:
sudo dpkg --force-all --purge mono-libraries
sudo dpkg --force-all --purge mono-devel mono-runtime mono-libraries-debug \
liblog4net1.2-cil keepass2-plugin-hibpofflinecheck
The exact package list depends on what is installed on your machine. Use dpkg -l | grep -i mono to find every Mono-related package, and include any applications that pulled them in (for example, a 3D-printing host application or a password-manager plugin). --force-all is aggressive, but here it is justified: these packages are already inconsistent, and you need dpkg to forget them entirely.
Errors during this step — dependency complaints, "package is in a very bad inconsistent state" messages — can be safely ignored as long as the purge ultimately completes.
Step 3: Clean Up with apt
Now let apt catch anything dpkg missed and repair dependency state:
sudo apt purge mono-libraries mono-devel mono-runtime
sudo dpkg --configure -a
sudo apt update
sudo apt --fix-broken install
If --fix-broken install tries to reinstall the Mono libraries again, that means something still depends on them. Either purge that dependent application as well, or — if you actually want Mono — make sure all Mono packages come from a single repository so the file ownership conflict disappears.
What Not to Do
- Do not delete files by hand. Removing the conflicting
.dllor GAC directory does nothing, because the error is about dpkg's package database, not the filesystem. - Do not force-purge unrelated libraries.
--force-allon non-Mono packages can break core desktop components and leave the system in worse shape. Keep the force-purge strictly scoped to the conflicting set. - Do not keep mixing Mono sources. Pick one — Ubuntu's universe repository or the official Mono repository — and stick with it.
Preventing a Recurrence
Before removing a metapackage or a framework like Mono, check what depends on it with apt rdepends --installed <package> or review apt's proposed transaction carefully instead of confirming blindly. When a removal goes wrong, stop and diagnose with apt policy and dpkg -l rather than attempting repeated install/remove cycles, which tend to deepen the inconsistency. Finally, if you have ever added a third-party repository, remove stale packages from it before switching sources — orphaned packages with no matching repository version are the most common trigger for overwrite conflicts like this one.
Frequently Asked Questions
Why did deleting the conflicting DLL not fix anything?
Dpkg rejects the unpack based on its package ownership database, not on the actual file contents. If two packages claim the same path, the error occurs regardless of whether the file exists on disk. Only purging one of the conflicting packages resolves the ownership conflict.
Is dpkg --force-all dangerous?
It can be, which is why it should be limited to the specific broken packages you are trying to remove. Used narrowly to purge an inconsistent package set, it is a standard recovery tool; used broadly, it can remove packages the system genuinely needs.
How do I find all Mono-related packages on my system?
Run dpkg -l | grep -i mono for packages with "mono" in the name, and also look for common Mono-dependent applications ( KeePass plugins, log4net libraries, certain printing or 3D-printing software). Those dependent packages often need to be purged in the same pass.
What does the repository suffix in a version string mean?
Strings like 0xamarin2+ubuntu2004b1 indicate the package was built for or distributed by a specific repository, in this case the upstream Mono project's Ubuntu packages. If apt policy shows that version only under /var/lib/dpkg/status and not under any configured repository, the package is orphaned and is a likely source of conflicts.
Can I reinstall Mono afterwards?
Yes. Once dpkg is consistent again and apt --fix-broken install completes without errors, install Mono from a single repository of your choice. Avoid mixing the Ubuntu-packaged versions with the upstream project's repository packages, since that is a frequent cause of this exact conflict.