-1

I tried to install Magick.NET, I installed using dotnet add package Magick.NET-Q8-x64 --version 7.21.1 that I got from https://www.nuget.org/packages/Magick.NET-Q8-x64/

I tried running a few lines of code that I got from https://stackoverflow.com/a/31829105/13924025 :

public string UploadFile(string fileName, IFormFile file)
    {
        string extension = System.IO.Path.GetExtension(file.FileName);
        string newFileName = "";
        if (fileName == null)
        {
            // newFileName = Guid.NewGuid ().ToString () + "-" + file.FileName;
            newFileName = Guid.NewGuid().ToString() + extension;
        }
        else
        {
            newFileName = Guid.NewGuid().ToString() + "-" + fileName + extension;
        }
        string filePath = "./Files/" + newFileName;

        using (MagickImage image = new MagickImage(file))
        {
          image.Scale(new Percentage(60));
          image.Write(filePath);
        }
        return newFileName;
    }

But I get an error "The type or namespace name 'MagickImage' could not be found". Are there any suggestions for resolving this?

  • The most common reason for this error is that you have failed to include the necessary `using` directive. Exactly as the error message says, as a matter of fact. There are a number of other related scenarios that can also cause the error. See marked duplicates for extensive discussion of all the possibilities. – Peter Duniho Jul 27 '20 at 04:40

1 Answers1

1

You need to add using ImageMagick; at the beginning of your C# file.

Vitaliy Shibaev
  • 1,420
  • 10
  • 24
  • Adding "using ImageMagick;" wasn't sufficient for me. I ended up installing two of the NuGet packages: "Magick.Net.Core" and "Magick.Net-Q16-x64". Then it started working. Not sure if that was logical or the best solution - the documentation in the NuGet package manager is lacking. But hey, at least it's working :-) – Ben Mockler Apr 08 '22 at 04:11