Error : Cannot implicitly convert type sitecore form data provider to 'Sitecore.ExperienceForms.Data.IFormDataProvider'.

I was trying to access form database to validate something but during instantiation of FormData provider interface I was getting issue because dot net  compiler only has knowledge of the method that takes a type.

ERROR:

private IFormDataProvider FormDataProviders = ServiceLocator.ServiceProvider.GetService(typeof(IFormDataProvider));



Severity
Code
Description
Project
File
Line
Suppression State
Error
CS0266
Cannot implicitly convert type 'object' to 'Sitecore.ExperienceForms.Data.IFormDataProvider'.



To fix above issue I just cast this Form data provider to it's interface. Once you cast thi service locator to form data provider then you can access sitecore form  entries from form database.



private IFormDataProvider FormDataProviders = (IFormDataProvider) ServiceLocator.ServiceProvider.GetService(typeof(IFormDataProvider));



Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'

Dot Net Core Application Packaging using Octo