{"record":{"id":"060456a807066aa1","repo":"JamesNK/Newtonsoft.Json","slug":"newtonsoft-json-support-for-dynamic-is-not-compati","errorCode":null,"errorMessage":"Newtonsoft.Json support for dynamic is not compatible with trimming and has been disabled. Newtonsoft.Json.Linq.JToken.DynamicIsSupported is set to false.","messagePattern":"Newtonsoft\\.Json support for dynamic is not compatible with trimming and has been disabled\\. Newtonsoft\\.Json\\.Linq\\.JToken\\.DynamicIsSupported is set to false\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JObject.cs","lineNumber":847,"sourceCode":"        }\n        #endregion\n\n#endif\n\n#if HAVE_DYNAMIC                            \n        /// <summary>\n        /// Returns the <see cref=\"DynamicMetaObject\"/> responsible for binding operations performed on this object.\n        /// </summary>\n        /// <param name=\"parameter\">The expression tree representation of the runtime value.</param>\n        /// <returns>\n        /// The <see cref=\"DynamicMetaObject\"/> to bind this object.\n        /// </returns>\n        protected override DynamicMetaObject GetMetaObject(Expression parameter)\n        {\n#if HAVE_APPCONTEXT\n            if (!DynamicIsSupported)\n            {\n                throw new NotSupportedException(DynamicNotSupportedMessage);\n            }\n#endif\n#pragma warning disable IL2026, IL3050\n            return new DynamicProxyMetaObject<JObject>(parameter, this, new JObjectDynamicProxy());\n#pragma warning restore IL2026, IL3050\n        }\n\n        private class JObjectDynamicProxy : DynamicProxy<JObject>\n        {\n            public override bool TryGetMember(JObject instance, GetMemberBinder binder, out object? result)\n            {\n                // result can be null\n                result = instance[binder.Name];\n                return true;\n            }\n\n            public override bool TrySetMember(JObject instance, SetMemberBinder binder, object value)\n            {","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JObject.cs#L829-L865","documentation":"Thrown by JObject.GetMetaObject (the IDynamicMetaObjectProvider surface) when dynamic-language binding is used against a JObject and the AppContext switch 'Newtonsoft.Json.Linq.JToken.DynamicIsSupported' is false. Dynamic dispatch on JObject relies on reflection/emission that trimming and Native AOT cannot support, so it is gated behind the switch.","triggerScenarios":"Using the C# 'dynamic' keyword (or any DLR binder) against a JObject — e.g. dynamic d = jObject; var x = d.SomeProperty; — in a trimmed/Native AOT app, or anywhere the switch 'Newtonsoft.Json.Linq.JToken.DynamicIsSupported' has been set to false.","commonSituations":"Publishing with trimming/Native AOT (the switch is flipped off), then writing dynamic d = JObject.Parse(json); accessing members dynamically; libraries that accept dynamic and forward JObjects.","solutions":["Stop using 'dynamic' with JObject; access properties via the string indexer: jObject[\"SomeProperty\"].","Deserialize into typed POCOs with JsonConvert.DeserializeObject<T>.","If dynamic access is essential, do not trim/AOT that path and set 'Newtonsoft.Json.Linq.JToken.DynamicIsSupported' to true in runtimeconfig."],"exampleFix":"// before\ndynamic d = JObject.Parse(json);\nvar name = d.Name; // NotSupportedException when trimmed\n\n// after\nvar o = JObject.Parse(json);\nvar name = (string)o[\"Name\"];\n// or\nvar model = JsonConvert.DeserializeObject<MyModel>(json);","handlingStrategy":"validation","validationCode":"bool dynamicSupported =\n    !AppContext.TryGetSwitch(\"Newtonsoft.Json.Linq.JToken.DynamicIsSupported\", out bool enabled)\n    || enabled;\nif (!dynamicSupported)\n    throw new InvalidOperationException(\"Dynamic access on JObject is disabled under trimming.\");","typeGuard":null,"tryCatchPattern":"try { dynamic d = jObject; var x = d.Name; }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"DynamicIsSupported\"))\n{\n    var x = (string)jObject[\"Name\"];\n}","preventionTips":["Do not use 'dynamic' with JObject; use the string indexer.","Deserialize into typed POCOs in trimmed/AOT apps.","If dynamic is required, do not trim and set the switch to true."],"tags":["newtonsoft-json","linq-to-json","dynamic","dlr","trimming","aot"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}