{"record":{"id":"2e490fd804601fd0","repo":"microsoft/garnet","slug":"could-not-initialize-lua-vm-innererror","errorCode":null,"errorMessage":"Could not initialize Lua VM: {innerError}","messagePattern":"Could not initialize Lua VM: (.+?)","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"critical","filePath":"libs/server/Lua/LuaRunner.cs","lineNumber":338,"sourceCode":"            var redisVersionParsed = Version.Parse(redisVersion);\n            var redisVersionNum =\n                ((byte)redisVersionParsed.Major << 16) |\n                ((byte)redisVersionParsed.Minor << 8) |\n                ((byte)redisVersionParsed.Build << 0);\n            state.PushInteger(redisVersionNum);\n            if (!state.TrySetGlobal(\"garnet_REDIS_VERSION_NUM\\0\"u8))\n            {\n                throw new GarnetException(\"Insufficient space in Lua VM for redis version number global\");\n            }\n\n            var loadRes = state.LoadBuffer(PrepareLoaderBlockBytes(allowedFunctions, logger).Span);\n            if (loadRes != LuaStatus.OK)\n            {\n                if (state.StackTop == 1 && state.Type(1) == LuaType.String)\n                {\n                    state.KnownStringToBuffer(1, out var buff);\n                    var innerError = Encoding.UTF8.GetString(buff);\n                    throw new GarnetException($\"Could not initialize Lua VM: {innerError}\");\n                }\n\n                throw new GarnetException(\"Could not initialize Lua VM\");\n            }\n\n            var sandboxRes = state.PCall(0, -1);\n            if (sandboxRes != LuaStatus.OK)\n            {\n                string errMsg;\n                try\n                {\n                    if (state.StackTop >= 1)\n                    {\n                        // We control the definition of LoaderBlock, so we know this is a string\n                        state.KnownStringToBuffer(1, out var errSpan);\n                        errMsg = Encoding.UTF8.GetString(errSpan);\n                    }\n                    else","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Lua/LuaRunner.cs#L320-L356","documentation":"Thrown while constructing a LuaRunner when the built-in Lua loader/sandbox block fails to load into the fresh Lua state. innerError is the message Lua itself pushed onto the stack (state.LoadBuffer returned non-OK and left a string). Because the loader block is shipped with Garnet (PrepareLoaderBlockBytes), a load failure usually means the Lua runtime and the embedded loader block are out of sync - a build/compatibility problem rather than user input.","triggerScenarios":"A LuaRunner instance is created (the first time a session uses FUNCTION LOAD, FCALL, or EVAL) and state.LoadBuffer(PrepareLoaderBlockBytes(...)) returns a status other than LuaStatus.OK with a string error on top of the Lua stack.","commonSituations":"Running a Garnet build whose Lua native dependency differs from the one the embedded loader block was authored against; a corrupted Garnet installation; mixing assemblies/binaries from different Garnet versions in one deployment.","solutions":["Reinstall/rebuild Garnet from a clean source tree so the Lua runtime and the embedded loader block match.","Confirm you are not mixing DLLs/binaries from different Garnet versions in the same deployment.","Capture the full innerError text in logs - it is the Lua compiler's own message and pinpoints the broken loader construct."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    runner = new LuaRunner(scriptSrc, ...);\n} catch (GarnetException ex) when (ex.Message.StartsWith(\"Could not initialize Lua VM\")) {\n    logger.LogCritical(ex, \"Lua runtime/loader mismatch; redeploy a consistent Garnet build\");\n    throw;\n}","preventionTips":["Deploy Garnet as a self-contained, version-matched package rather than swapping individual assemblies.","Log the full exception message - the embedded innerError identifies the exact Lua load failure."],"tags":["lua","scripting","initialization","version-mismatch"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}