I am using crystal reports RAS SDK to make changes in rpt file dynamically through code. For this I am doing a POC to check how to use report templates programmatically. There is an assembly CrystalDecisions.CrystalReports.TemplateEngine which contains all the classes for report templates.
But when I am trying to create an instance of ReportTemplateEngine using code below, I am receiving an error.
Code snippet:
Dim templateEngineActual AsISCRReportTemplateEngine=NewReportTemplateEngine
This line throws an error:
System.Runtime.InteropServices.COMException was caught
ErrorCode=-2147221164
Message=Retrieving the COM class factory for component with CLSID {B932BBA7-8A8F-4A32-B510-C6216345BEC5}
failed due to the following error:80040154Classnot registered (Exceptionfrom HRESULT:0x80040154(REGDB_E_CLASSNOTREG)).
Source=mscorlib StackTrace: at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) at
System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType,Object[] props,Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache) at
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,Boolean skipVisibilityChecks,Boolean skipCheckThis,Boolean fillCache)
at System.Activator.CreateInstance(Type type,Boolean nonPublic) at System.Activator.CreateInstance(Type type)
at CrystalReportsPOC.Form1.ChangeTemplate1(ISCDReportClientDocument targetRCD)in C:\Users\saurabh.agarwal\Desktop\CrystalReportsPOC\CrystalReportsPOC\Form1.vb:line 235
at CrystalReportsPOC.Form1.Form1_Load(Object sender,EventArgs e)in C:\Users\saurabh.agarwal\Desktop\CrystalReportsPOC\CrystalReportsPOC\Form1.vb:line 26
Steps taken:
I checked the GAC and found two entries for CrystalDecisions.CrystalReports.TemplateEngine assembly. One for MSIL and another for AMD64. After that I checked the registry entries. There was no registry entry for the CLSID in error description. I registered this assembly using regasm command but no benefit came up.
Now I can find the CLSID (shown in error) in registry and in registry it displays class value : ReportTemplateEngineClass.
But still I cannot create an instance of reportTemplateEngine. Please suggest me what I am doing wrong.
Environment details:
VisualStudio2010 SP1 Dotnet frameworrk :4.0 CPU Mode: x86 CrystalReportsVersion:2013