RDLC Report Error System.NullReferenceException on asp.net core

jewel 1,186 Reputation points
2024-12-31T15:05:44.51+00:00
I am stuck with a Great problem. When I am moving from one controller to another controller in my RDLC report and going to view the report the parameter error is coming. That is, after running the program, only one controller report is visible. If i look at the report of another controller, the error is coming.

After searching a lot, I can't find a solution to this problem anywhere. It would be great if the experts could help.
I am using Asp .NET Core 8.0.
and For Rdlc Report Add  Windows Forms App> .Net8.0

//This is TestController Code 
using AspNetCore.Reporting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Rdlc1.Data;
using Rdlc1.Models;
namespace Rdlc1.Controllers
{
    public class TestController : Controller
    {
        private ApplactionDbContext _context;
        private readonly UserManager<Appplactionuser> _userManager;
        private readonly IWebHostEnvironment _webHostEnvironment;
        public TestController(ApplactionDbContext context, UserManager<Appplactionuser> userManager, IWebHostEnvironment webHostEnvironment)
        {
            _context = context;
            _userManager = userManager;
            this._webHostEnvironment = webHostEnvironment;
        }
     
        public IActionResult Testprint()
        {
            int ext = (int)(DateTime.Now.Ticks >> 10);
            String path = _webHostEnvironment.WebRootPath + @"\Reports\Report1.rdlc";
            Dictionary<String, string> parmeter = new Dictionary<String, string>();
            
            parmeter.Add("prm", "jewel");
            var Data = _context.tbl_Companies.ToList();
            LocalReport localreport = new LocalReport(path);
            localreport.AddDataSource("DataSet1", Data);
            var report = localreport.Execute(RenderType.Pdf, ext, parmeter, "");
            return File(report.MainStream, "application/pdf");
        }
    }
}

//This is HomeController Code 

using System.Diagnostics;

using AspNetCore.Reporting;

using Microsoft.AspNetCore.Identity;

using Microsoft.AspNetCore.Mvc;

using Rdlc1.Data;

using Rdlc1.Models;

namespace Rdlc1.Controllers

{

public class HomeController : Controller

{

    private ApplactionDbContext _context;

    private readonly UserManager<Appplactionuser> _userManager;

    private readonly IWebHostEnvironment _webHostEnvironment;

    public HomeController(ApplactionDbContext context, UserManager<Appplactionuser> userManager, IWebHostEnvironment webHostEnvironment)

    {

        _context = context;

        _userManager = userManager;

        this._webHostEnvironment = webHostEnvironment;

    }

   

    public IActionResult Testprint()

    {

        int ext = (int)(DateTime.Now.Ticks >> 10);

        String path = _webHostEnvironment.WebRootPath + @"\Reports\Report2.rdlc";

        Dictionary<String, string> parmeter = new Dictionary<String, string>(); 

        parmeter.Add("nws", "jewel");

        var Data = _context.tbl_Companies.ToList();

        LocalReport localreport = new LocalReport(path);

        localreport.AddDataSource("DataSet1", Data);

        var report = localreport.Execute(RenderType.Pdf, ext, parmeter, "");

        return File(report.MainStream, "application/pdf");

    }

}

}

record_2

Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. jewel 1,186 Reputation points
    2025-01-29T13:13:44.7533333+00:00

    Untitled

    When do this, Problem Solved.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.