.net core Class Library as an ObjectDataSource

9 posts, 0 answers
  1. Bob
    Bob avatar
    11 posts
    Member since:
    Jul 2010

    Posted 31 Jan Link to this post

    I've been experimenting using the stand alone report designer with an objectdatasource. After updating the ReportDesigner config file to include the assembly names, the only assemblies that appear are those that are created with the .net framework. Assemblies created with .net core are not visible. Is this correct behavior? Or is there something I need to add to the the .net core class library so they are visible?
  2. Katia
    Admin
    Katia avatar
    693 posts

    Posted 05 Feb Link to this post

    Hello Bob,

    ASP.NET Core Class Library projects are not supported. Reporting engine is built against full .NET framework, therefore, it cannot discover types in .NET Core Class Library project. We will update our documentation to include this information as well.

    The solution is to keep custom data objects in full .NET Class Library project.

    Regards,
    Katia
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Bob
    Bob avatar
    11 posts
    Member since:
    Jul 2010

    Posted 05 Feb in reply to Katia Link to this post

    Katia,

    Thanks for the confirmation.

  4. yceron
    yceron avatar
    25 posts
    Member since:
    Apr 2007

    Posted 28 Jun in reply to Katia Link to this post

    Any update on when this will be supported?
  5. Todor
    Admin
    Todor avatar
    175 posts

    Posted 03 Jul Link to this post

    Hello yceron,

    We use Microsoft service (ITypeResolutionService form the System.ComponentModel of the .NET Framework) to resolve the types. The service cannot discover the .NET Core ClassLibrary types, hence we cannot resolve types from .NET Core projects.

    Note that the ObjectDataSource supports .NET Standard projects. We have tested it with .NET Standard 2.0.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. yceron
    yceron avatar
    25 posts
    Member since:
    Apr 2007

    Posted 04 Jul in reply to Todor Link to this post

    Thank you for your response.

    I tried creating a report inside Visual Studio 2017.  I have .Net 4.6.1 class library with my report. This class references Telerik Reporting 12.1.18.516.  I was able to create a report with an ObjectDataSource that talks to a .Net Standard 2.0 class library as you suggested. When I click on the preview tab I get a "Could not load type" exception with the name of the obect in my .Net Standard 2.0 class library.

    I have the following on the App.config for said class library.
    <Telerik.Reporting>
     <assemblyReferences>
               <add name="Payroll.Core" version="1.0.0.0" />
           </assemblyReferences>
    </Telerik.Reporting>


    I tried rendering the report on a Asp.Net Core 2.1 website that has .net 461 as the target framework <TargetFramework>net461</TargetFramework>

    When I try to render the report (as a PDF) I get the same "Could not load type" exception with the name of the obect in my .Net Standard 2.0 class library. I tried adding an app.config file to the web application with the <Telerik.Reporting>  <assemblyReferences> section.

    I'm directly rendering the PDF with a code similar to this one:

    var telerikReport = new ReportObjects.Payrolls.PayrollInstanceReport();
     
    Telerik.Reporting.Report report;
     
    ReportProcessor reportProcessor = new ReportProcessor();
    Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
    instanceReportSource.ReportDocument = telerikReport;
     
    RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
    return result.DocumentBytes;

    Is this scenario not supported at the moment under asp.net core, or am I missing something?

     

  7. Todor
    Admin
    Todor avatar
    175 posts

    Posted 09 Jul Link to this post

    Hello yceron,

    I tested the approach locally. It works fine on our side.

    Make sure that your .Net Standard 2.0 Class Library is properly referred in the other projects.

    I have attached my sample test solution for your reference.
    There are three projects:
    1. WebApplication2 - a .NET Core 2.1 Application targeting .NET Framework 4.6.1
    2. DotNetStandardClassLibrary - a .NET Standard 2.0 Class Library that provides data to the ObjectDataSource
    3. ClassLibrary1 - a .NET Framework 4.6.1. Class Library where the report is defined

    By selecting 'Viewer' from the main menu you will open the report in the viewer.
    By selecting "PDF" you will trigger PDF Export - I have used the provided code.

    You can test the sample, compare it with your application, and adjust the latter if necessary.

    Note that instead of creating an instance of the Reporting Engine to export the report to PDF you can use our REST Service API where the latter is already instantiated.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. yceron
    yceron avatar
    25 posts
    Member since:
    Apr 2007

    Posted 18 Jul in reply to Todor Link to this post

    Thank you for the sample.

    After playing around more with this, my problem seems to be with injecting services.  I'm using asp.net core and taking advantage of the built in dependency injection.  When my injected services get to the report class, on the NeedDataSource which is where I'm populating the data, things like DbContext are not available anymore, it says it has been already disposed. I also have another service, that returns data from the current user principal as well as the request headers, these are null when they get to the NeedDataSource on the report.

    Could you confirm if an scenario like what I described is supported under the current version? Is it possible to inject the dbContext and user principal services into the report?

    Thanks again.

  9. Silviya
    Admin
    Silviya avatar
    183 posts

    Posted 23 Jul Link to this post

    Hi yceron,

    Firstly, our recommendation is to avoid using events when data binding the reports, except really necessary. In this case I cannot determine why the NeedDataSource should be used, rather than declaratively configure the data source in the report definition.

    Anyways, it would be needed to either use the EntityDataSource component so that we can create the DbContext object internally, or create and use DbContext instance in the NeedDataSource event handler. To access the current user context, you can use the Telerik.Reporting.Processing.UserIdentity.Current static property. It is also possible to use the new UserIdentity object in the expression context as a global object: =UserIdentity.
    The UserIdentity.Context property can be used to store user objects.

    Regards,
    Silviya
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top