Access violation from IServiceLocator.GetAllService()

44 views
Skip to first unread message

Morten Nissen

unread,
Jan 30, 2025, 6:34:44 AMJan 30
to Spring4D
Hi im having some issues getting the IServiceLocator.GetAllServices() to work.
It seems to just throw an access violation.

The issue also happens in the EventDrivenArchitecture example. So it should be fairly easy to replicate :)

Im using Delphi 12.2 building for Win32 with Spring4D version 2.0.1

If there is anyone that can point me to a fix. Or if i should just try and create it as an issue on the bitbucket repository. Tried to see if one existed and couldnt find it :)

Stefan Glienke

unread,
Jan 30, 2025, 7:01:22 AMJan 30
to Spring4D
This probably broke some while ago when I disabled RTTI for many classes inside the library that usually are not used in any context that requires those.
The quick fix (which you need to apply yourself) is to add the following line above TServiceLocatorAdapter in Spring.Container.pas:

{$IFDEF DELPHIXE6_UP}{$RTTI EXPLICIT METHODS(DefaultMethodRttiVisibility)}{$ENDIF}

The proper fix is to not use the IServiceLocator (which I have been telling for years not to use) and solve this in the proper DI way: using the factory pattern.
When time permits I will fix the EventDrivenArchitecture demo to do so
Reply all
Reply to author
Forward
0 new messages