Update ServiceExtensions.cs

Fix invalid Cast