{"record":{"id":"2ba26b010f2755c7","repo":"Unity-Technologies/UnityCsReference","slug":"relayed-from-caught-exception-e-message-filepat","errorCode":null,"errorMessage":"<relayed from caught exception: e.Message, FilePath=path>","messagePattern":"<relayed from caught exception: e\\.Message, FilePath=path>","errorType":"exception","errorClass":"AssemblyDefinitionException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs","lineNumber":355,"sourceCode":"                var filePaths = new List<string> {loadedCustomScriptAssembly.FilePath};\n                filePaths.AddRange(duplicateFilePaths);\n\n                throw new AssemblyDefinitionException(\n                    $\"Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files\",\n                    filePaths.ToArray());\n            }\n        }\n\n        public static CustomScriptAssembly LoadCustomScriptAssemblyFromJson(string path, string json, string guid)\n        {\n            try\n            {\n                var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);\n                return CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData);\n            }\n            catch (Exception e)\n            {\n                throw new AssemblyDefinitionException(e.Message, path);\n            }\n        }\n\n        public static CustomScriptAssembly LoadCustomScriptAssemblyFromJsonPath(string path, string guid)\n        {\n            var json = Utility.ReadTextAsset(path);\n\n            try\n            {\n                var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);\n                return CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData);\n            }\n            catch (Exception e)\n            {\n                throw new AssemblyDefinitionException(e.Message, path);\n            }\n        }\n","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs#L337-L373","documentation":"LoadCustomScriptAssemblyFromJson (LoadingAssemblyDefinition.cs:355) wraps ANY exception thrown while deserializing an asmdef's JSON and building the CustomScriptAssembly (e.g. JSON parse errors, or the validation failures from errors 700/701/702/703) into an AssemblyDefinitionException whose filePaths carries the source .asmdef path. The original cause is only preserved as the wrapped exception's Message string, not its stack/type.","triggerScenarios":"Malformed .asmdef JSON, a missing 'name', a failed ValidateFields (both platform arrays set, codegen+autoReferenced), or an invalid define constraint / platform name encountered while loading from a JSON string.","commonSituations":"Hand-editing an asmdef and introducing a syntax error. External tooling writing invalid asmdef JSON. Copying a partial asmdef.","solutions":["Read the AssemblyDefinitionException.Message (it relays the inner exception's message) and the filePaths[0] to locate the offending asmdef, then fix the underlying content issue described by that inner message.","Validate the .asmdef JSON with a JSON linter and Unity's asmdef schema before reimporting."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var asm = CustomScriptAssembly.LoadCustomScriptAssemblyFromJson(path, json, guid);\n}\ncatch (AssemblyDefinitionException ex)\n{\n    // ex.Message relays the inner cause; ex.filePaths[0] is the .asmdef path\n    LogError($\"Failed to load asmdef '{string.Join(\", \", ex.filePaths)}': {ex.Message}\");\n    // surface to the user as an import error; do not swallow\n}","preventionTips":["Validate .asmdef JSON against Unity's asmdef schema before feeding it to the loader.","When generating asmdefs programmatically, round-trip them through the schema validator first.","Always inspect ex.filePaths to attribute the failure to the correct source file."],"tags":["unity","asmdef","script-compilation","json","relayed"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}