In this article, we will learn how to solve The base class includes the field ‘ReportViewer1’ but its type is not compatible with the type of control “Microsoft.Reporting.WebForms.ReportViewer” that you may face when adding a new Microsoft.Reporting.WebForms.ReportViewer reference to your ASP.NET or SharePoint solution.
The base class includes the field ‘ReportViewer1’ but its type is not compatible
In ASP.NET and SharePoint Solution, I have tried to add a “Report Viewer” control to visual web part but, I got the below error:
The base class includes the field ‘ReportViewer1’ but its type (Microsoft.Reporting.WebForms.ReportViewer) is not compatible with the type of control (Microsoft.Reporting.WebForms.ReportViewer)
I have checked the references in the SharePoint Solution, I had noticed that The “Microsoft.Reporting.WebForms” reference is not added!
I added the “Microsoft.Reporting.WebForms” reference then I tried to deploy the SharePoint solution again. but I got a new error as shown below:
CS0433: The type ‘Microsoft.Reporting.WebForms.ReportViewer’ exists in both ‘c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms \10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll’ and ‘c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms \9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dl
The type ‘Microsoft.Reporting.WebForms.ReportViewer’ exists in both
Cause
This issue usually occurs in case of the Microsoft.Reporting.WebForms.ReportViewer reference version that attached to the SharePoint Solution is not matched with the reference version that already registered in the Web.config file of the SharePoint Web Application.
In my case, the SharePoint solution has the reference “Microsoft.ReportViewer.WebForms” version 10. Meanwhile, the Web.config of the SharePoint Web Application has the reference “Microsoft.ReportViewer.WebForms” Version 9.
Solution
The solution for this issue is removing the old Microsoft.Reporting.WebForms.ReportViewer reference and add the new one as the following:
Steps
- Match the two version numbers in the SharePoint Solution & Web.Config,
- Register the reference in the web part as the following:
- In SharePoint Solution, remove the “Microsoft.ReportViewer.WebForms” Version 10.
- Add “Microsoft.ReportViewer.WebForms” reference Version 9.
- Register the assembly tag in the front code of the visual web part.
Conclusion
In conclusion, we have learned how to register Microsoft.ReportViewer.WebForms reference in a SharePoint solution to avoid the below mismatching issues:
- The base class includes the field ‘ReportViewer1’ but its type is not compatible.
- The type ‘Microsoft.Reporting.WebForms.ReportViewer’ exists in both.
Applies To
- SharePoint 2016.
- SharePoint 2013.
- .Net Solution.
- Report Viewer.
See Also
- Reporting Service render issue within Report Viewer Webpart in SharePoint Server 2013 with IE 10 or later.
- SSRS Report Viewer Webpart Error: s.ArgumentNullException : Value cannot be null.
- SharePoint 2016: A strongly-named assembly is required
- Solving Could not load type system.servicemodel.activation.httpmodule from assembly System.ServiceModel
- SQL Reporting service SharePoint 2016.
Perfect!!
Perfect, thanks for the explanation