{"record":{"id":"df1b20f061900d89","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"specified-property-is-not-of-string-type","errorCode":null,"errorMessage":"Specified property is not of string type","messagePattern":"Specified property is not of string type","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Localising/LocalisedNameAttribute.cs","lineNumber":46,"sourceCode":"        private string ResourceName { get; }\n        private Type ResourceType { get; }\n\n        public string GetName()\n        {\n            if (NameOverride != null)\n                return NameOverride;\n\n            if ((ResourceType != null) && (ResourceName != null))\n            {\n                var property = ResourceType.GetProperty(ResourceName,\n                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);\n                if (property == null)\n                {\n                    throw new InvalidOperationException(\"Resource of this type doesn\\'t contain specified property\");\n                }\n                if (property.PropertyType != typeof (string))\n                {\n                    throw new InvalidOperationException(\"Specified property is not of string type\");\n                }\n                return (string) property.GetValue(null, null);\n            }\n            return string.Empty;\n        }\n    }\n}","sourceCodeStart":28,"sourceCodeEnd":53,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Localising/LocalisedNameAttribute.cs#L28-L53","documentation":"Thrown by LocalisedNameAttribute.GetName() immediately after the property is found. It requires the resolved property's PropertyType to be exactly typeof(string); any other type (int, object, byte[], etc.) raises InvalidOperationException. This guards the subsequent (string)property.GetValue(null,null) cast.","triggerScenarios":"The ResourceName resolves to a resource property whose generated type is not string, e.g. a RESX entry typed as an image/icon/byte[] via the designer, or a manually added non-string static property on the resource class.","commonSituations":"Adding an image/file resource with the same key as a text resource, using a custom partial resource class that adds a non-string static member, or upgrading a resource whose type changed between versions.","solutions":["Ensure the RESX entry for that key is a text/string value, not a file/binary resource.","Rename the conflicting non-string resource and update ResourceName to a string-only key.","If you need a typed resource, use ResourceManager.GetObject directly instead of this attribute."],"exampleFix":"// before: RESX has \"Logo\" as System.Drawing.Bitmap\n[LocalisedName(ResourceType = typeof(Strings), ResourceName = \"Logo\")] // throws\n\n// after: add a string entry \"LogoName\" and reference it\n[LocalisedName(ResourceType = typeof(Strings), ResourceName = \"LogoName\")]","handlingStrategy":"validation","validationCode":"var prop = typeof(Strings).GetProperty(keyName,\n    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);\nif (prop != null && prop.PropertyType != typeof(string))\n    logger.Error($\"Resource {keyName} is {prop.PropertyType}, expected string\");","typeGuard":"static bool IsStringResource(Type resType, string key)\n    => resType.GetProperty(key, BindingFlags.Public | BindingFlags.Static)?.PropertyType == typeof(string);","tryCatchPattern":"try { attr.GetName(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not of string type\"))\n{ /* use member.Name as fallback */ }","preventionTips":["Keep text and binary resources in separate RESX files to avoid key collisions.","Add a build-time test asserting all LocalisedName keys point to string properties.","Audit RESX entries when adding non-text resources (icons, images)."],"tags":["resources","localisation","type-mismatch","csharp","kloctools"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}