{"record":{"id":"e4187bedc30e54aa","repo":"louthy/language-ext","slug":"2000000007-the-io-monad-is-not-in-the-monad-transformer","errorCode":"-2000000007","errorMessage":"The IO monad is not in the monad-transformer stack or MonadIO.LiftIO has not been implemented in the trait implementation for your monad-type.  Therefore it's not possible to leverage `MonadIO` lifting functionality. To resolve this, implement `MonadIO.LiftIO`.","messagePattern":"The IO monad is not in the monad-transformer stack or MonadIO\\.LiftIO has not been implemented in the trait implementation for your monad-type\\.  Therefore it's not possible to leverage `MonadIO` lifting functionality\\. To resolve this, implement `MonadIO\\.LiftIO`\\.","errorType":"error_code","errorClass":"ExceptionalException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Traits/Maybe Traits/MonadIO/MonadIO.Trait.cs","lineNumber":42,"sourceCode":"        /// <summary>\n        /// Lifts the IO monad into a monad transformer stack.  \n        /// </summary>\n        /// <remarks>\n        /// IMPLEMENTATION REQUIRED: If this method isn't overloaded in this monad\n        /// or any monad in the stack on the way to the inner-monad, then it will throw\n        /// an exception.\n        ///\n        /// This isn't ideal, it appears to be the only way to achieve this\n        /// kind of functionality in C# without resorting to magic. \n        /// </remarks>\n        /// <param name=\"ma\">IO computation to lift</param>\n        /// <typeparam name=\"A\">Bound value type</typeparam>\n        /// <returns>The outer monad with the IO monad lifted into it</returns>\n        /// <exception cref=\"ExceptionalException\">If this method isn't overloaded in\n        /// the inner monad or any monad in the stack on the way to the inner-monad,\n        /// then it will throw an exception.</exception>\n        public static virtual K<M, A> LiftIOMaybe<A>(IO<A> ma) =>\n            throw new ExceptionalException(Errors.LiftIONotSupported);\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":45,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Traits/Maybe Traits/MonadIO/MonadIO.Trait.cs#L24-L45","documentation":"MonadIO.LiftIOMaybe's default trait implementation throws ExceptionalException (code -2000000007) because neither the target monad M nor any monad in its transformer stack implements LiftIO. The library cannot lift IO<A> into M without an explicit implementation somewhere in the stack.","triggerScenarios":"Calling LiftIOMaybe<A>(IO<A>) on a monad whose trait implementation does not override LiftIO and which contains no MonadIO-implementing transformer.","commonSituations":"Custom monads without MonadIO support, or using a transformer stack missing the IO-handling layer; common when writing generic code parameterised on M.","solutions":["Implement/override MonadIO.LiftIO in your monad's trait implementation","Insert a transformer (e.g. IOT) into the stack that provides LiftIO","Avoid LiftIO for that monad; keep IO at the outer edge of your program"],"exampleFix":"// before\npublic static virtual K<M, A> LiftIOMaybe<A>(IO<A> ma) => throw new ExceptionalException(Errors.LiftIONotSupported);\n// after\npublic static K<M, A> LiftIO<A>(IO<A> ma) => // in your MonadIO<M> trait impl\n    map(ma.Run, x => pure(x));","handlingStrategy":"try-catch","validationCode":"// static check: typeof(MonadIO<M>).GetMethod(\"LiftIO\") is overridden before calling LiftIOMaybe","typeGuard":"bool CanLiftIO<M>() => typeof(MonadIO<M>).GetMethod(\"LiftIO\")!.DeclaringType != typeof(MonadIO<M>);","tryCatchPattern":"try { return LiftIOMaybe(ma); }\ncatch (ExceptionalException ex) when (ex.Code == Errors.LiftIONotSupported.Code) { /* use non-IO path */ }","preventionTips":["Implement LiftIO in every custom MonadIO trait","Keep IOT in transformer stacks that must interact with IO","Test LiftIO support when introducing new monads"],"tags":["csharp","languageext","monadio","io"],"backgroundTag":"method-not-implemented","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}