Error when using Harmony 2 with MelonLoader: 'Harmony' is a namespace but is used like a type

6 days ago 4
ARTICLE AD BOX

There is both Harmony the namespace (from MelonLoader) and Harmony the type. It's unfortunate that the MelonLoader authors did that, to be honest... however, there are options to stop it from being a problem:

First option: qualify the usage:

HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.xbeardeddice.examplemod");

This becomes shorter if you use var:

var harmony = new HarmonyLib.Harmony("com.xbeardeddice.examplemod");

Second option: create an alias:

using HarmonyClass = global::HarmonyLib.Harmony; ... HarmonyClass harmony = new HarmonyClass("com.xbeardeddice.examplemod");

Jon Skeet's user avatar

1 Comment

Thanks--unfortunately there's no MelonLoader tag (and I don't feel like putting in the effort to create one right now) but I've updated the title of the question to reflect the key issue here: conflicts between the Harmony 2 and MelonLoader libs.

2026-01-28T14:47:19.023Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article