{"record":{"id":"d8044d28f1dba356","repo":"abpframework/abp","slug":"could-not-find-an-object-of-typeof-t-assemblyqua","errorCode":null,"errorMessage":"Could not find an object of {typeof(T).AssemblyQualifiedName} in services. Be sure that you have used AddObjectAccessor before!","messagePattern":"Could not find an object of (.+?) in services\\. Be sure that you have used AddObjectAccessor before!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionObjectAccessorExtensions.cs","lineNumber":52,"sourceCode":"        }\n\n        //Add to the beginning for fast retrieve\n        services.Insert(0, ServiceDescriptor.Singleton(typeof(ObjectAccessor<T>), accessor));\n        services.Insert(0, ServiceDescriptor.Singleton(typeof(IObjectAccessor<T>), accessor));\n\n        return accessor;\n    }\n\n    public static T? GetObjectOrNull<T>(this IServiceCollection services)\n        where T : class\n    {\n        return services.GetSingletonInstanceOrNull<IObjectAccessor<T>>()?.Value;\n    }\n\n    public static T GetObject<T>(this IServiceCollection services)\n        where T : class\n    {\n        return services.GetObjectOrNull<T>() ?? throw new Exception($\"Could not find an object of {typeof(T).AssemblyQualifiedName} in services. Be sure that you have used AddObjectAccessor before!\");\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionObjectAccessorExtensions.cs#L34-L55","documentation":"Thrown by ServiceCollectionObjectAccessorExtensions.GetObject<T> when no IObjectAccessor<T> has been registered (so the underlying value is null). The message reminds the caller to call AddObjectAccessor first. This is the read-side counterpart to error 233.","triggerScenarios":"Calling services.GetObject<T>() before any AddObjectAccessor<T>() has registered the accessor — e.g. reading IAbpHostEnvironment or IConfiguration during ConfigureServices before the host wired it.","commonSituations":"Accessing a framework accessor during module registration before the generic host has populated it; misordered startup; custom code resolving an accessor ABP never adds in the current hosting model.","solutions":["Register the accessor with AddObjectAccessor<T>() / TryAddObjectAccessor<T>() before calling GetObject<T>().","Use GetObjectOrNull<T>() if the value may legitimately be absent and handle the null case.","Reorder startup so the accessor is populated before dependent code reads it (often move the read into OnApplicationInitialization)."],"exampleFix":"// before — accessor never added\nvar cfg = services.GetObject<IConfiguration>();\n\n// after — register first\nservices.AddObjectAccessor<IConfiguration>(myConfiguration);\nvar cfg = services.GetObject<IConfiguration>();\n// or tolerate absence\nvar cfg = services.GetObjectOrNull<IConfiguration>();","handlingStrategy":"validation","validationCode":"// Use the OrNull variant and register the accessor first when needed\nvar value = services.GetObjectOrNull<T>();\nif (value == null)\n{\n    services.TryAddObjectAccessor<T>();\n    // populate as needed, then read again\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register the accessor (TryAddObjectAccessor) before reading it.","Use GetObjectOrNull<T>() when absence is acceptable.","Move reads into OnApplicationInitialization where accessors are populated."],"tags":["dependency-injection","object-accessor","startup","abp-core"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}