Error CS0246: The type or namespace name 'Color' could not be found

I am migrating an application from .NET Framework 4.6.1 to .NET Core 3.1. I added the following nuget reference to the new project: FastReport.OpenSource - 2019.2.0 (to match the version of dlls used in the old project)


Everything works fine, the code compiles easily, until I ran the code and hit the report.Prepare(true); instruction. I get the following error:

(102,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(108,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(114,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(120,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(126,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(132,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(138,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(144,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(150,18): Error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

(104,15): Error CS0103: The name 'Color' does not exist in the current context

(110,15): Error CS0103: The name 'Color' does not exist in the current context

(116,15): Error CS0103: The name 'Color' does not exist in the current context

(122,15): Error CS0103: The name 'Color' does not exist in the current context

(128,15): Error CS0103: The name 'Color' does not exist in the current context

(134,15): Error CS0103: The name 'Color' does not exist in the current context

(140,15): Error CS0103: The name 'Color' does not exist in the current context

(146,15): Error CS0103: The name 'Color' does not exist in the current context

(152,15): Error CS0103: The name 'Color' does not exist in the current context

(70,29): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(76,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(77,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(80,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(81,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(84,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(85,26): Error CS0012: The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

(85,38): Error CS0103: The name 'Color' does not exist in the current context


Here is the code:

using var report = new Report();
using var reportTemplate = new MemoryStream(Resources.ReportFile); // Our CustomReport.frx

report.Load(reportTemplate);

// Setting some parameters
report.SetParameterValue([..]);

// Registering some data
report.RegisterData([..])

report.Prepare(true);


The frx file contains, in its script part, 9 custom defined colors, like this:

 public static Color ErrorAlarm{
     get{
       return Color.FromArgb(255, 48, 48);
     }
   }

So I suspect the issue is probably linked to this. But I don't understand why FastReport is complaining about System.Drawing.Primitives, since it exists in .NET Core 3.1...


I also tried to upgrade the FastReport.OpenSource to newer versions (including the last one), but I always get either the same error or a NullReferenceException, when the program hit report.Prepare(true).

Comments

  • web or desktop app?

  • Migrating from Desktop to Web.


    I saw there is a FastReport.OpenSource.Web package. What does it bring? I only need to generate a PDF.

  • for PDF, https://www.nuget.org/packages/FastReport.OpenSource.Export.PdfSimple/

    but, it sucks, result file is too large.

    to solve the problem, try to export CustomReport.frx to cs class, then build the project
    


  • I am sorry but I can't find how to export my frx file to cs class... Is it an option in the designer or something?

  • Found out ! It was hidden into Save As in the designer, and not an Export action. I check this out immediately ! Thank you

  • open frx file with designer, then menu-> file -> save as -> cs file

  • edited February 2021

    Well, exporting into cs classes help me to fix the NullReferenceException I had with the newest versions of the package (a bad index in the data I bound to the template). This does not explain the initial issue (The type or namespace name 'Color' could not be found) but it's okay for me, since I can upgrade to a new version.


    And I can see now why you told me the SimplePDF export sucks. Not only the size, but the pdf quality is also very poor. In the desktop application, the export was working way better. Is there a reason why the PDFExport class does not exist anymore?

  • Hello!

    Please update the FastReport.OpenSource (and FastReport.Compat) package to the latest version

    If it is essential to remain on the old version: install the System.Drawing.Common NuGet package, add `using System.Drawing;` to the header of the report script, and add `System.Drawing.Primitives.dll` / `System.Drawing.Common.dll` to `report.ReferencedAssemblies`.

This discussion has been closed.