0

i have this issue:

1) I've downloaded Magick.NET-Q16-AnyCPU throught NUGET in VS2010. 2) I've created this function for read remote svg and convert it into itextSharp.text.Image object as below:

iTextSharp.text.Image headeImage = null;

using (MagickImage image= new MagickImage(linksvgremote))
{ 
   Percentage percent = new Percentage(55);
   image.Resize(percent);
   headeImage = iTextSharp.text.Image.GetInstance(image.ToByteArray(MagickFormat.Png));

}

Javascript function is:

 ApriDialogCaricamento();  
  var datiInput = {};

    datiInput.idTipo = idtipo;
    datiInput.clearEngine = clearengine;
    datiInput.nomeFileSvg = numfile;

    var jsonData = JSON.stringify(datiInput);

    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {

            ChiudiDialogCaricamento();

            var url = window.URL || window.webkitURL;
            window.open(url.createObjectURL(this.response));
        }
    }

    xhr.open('POST', 'handlers/generaDatiTecniciPDF.ashx');
    xhr.responseType = 'blob';
    xhr.setRequestHeader('Content-Type', 'application/pdf');
    xhr.send(jsonData); 

It's work fine local but when i have uploaded on iis server the javascript function return this string:

failed to load resource the server responded with a status of 500 (internal server error)

It's would say that the problem is in function descripted above.... i know it because if i comment it it works but not generate the svg-converted-image .

How can i resolve it on my server?

Thanks

Mike

Mike Vinyl
  • 97
  • 1
  • 9
  • Can't you try to download the picture using a `WebClient` first and use another constructor for `MagickImage`? What's the link? It's hard to tell what request has been executed inside that library for debugging. – Maximilian Gerhardt May 09 '16 at 09:55
  • Not now... i would want resolve the problem.... – Mike Vinyl May 09 '16 at 09:57
  • Clarification please: You're talking about a *javascript* function but don't give us the code to. Is there an exception within the given C# code? I though the error occurs when `linksvgremote` is like `http://..../a.svg` and the code received a `500` trying to download the link which is triggered by the constructor. Is this right? – Maximilian Gerhardt May 09 '16 at 10:00
  • The link is here : https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/beacon.svg. – Mike Vinyl May 09 '16 at 10:02
  • I think it's right Maximilian..... pls...help me.. – Mike Vinyl May 09 '16 at 10:04
  • Post the complete code of the function handling that request. Also, take a look at the stacktrace the POST request maybe gives you so you can start debugging. It could have to do something with the `https`, which could be circumvented using a `WebClient` as proposed in http://stackoverflow.com/questions/20955833/error-with-download-a-file-from-https-using-webclient . – Maximilian Gerhardt May 09 '16 at 10:13
  • It's the Magick.Net must be installed on server too? – Mike Vinyl May 09 '16 at 10:15
  • It only needs the `.dll`s referenced in the project, nothing else. (`Magick.NET embeds all the ImageMagick files`). Can you already post a stacktrace when the C# function fails? Look in your browsers `Network Connections` for the response html. – Maximilian Gerhardt May 09 '16 at 10:23
  • I have extracted with try catch the exception for the code and i found this exception: The type initializer for 'X86' threw an exception. at ImageMagick.MagickSettings.NativeMethods.X86.MagickSettings_Create() at ImageMagick.MagickSettings.NativeMagickSettings..ctor() at ImageMagick.MagickSettings..ctor() at ImageMagick.MagickImage..ctor() at ImageMagick.MagickImage..ctor(String fileName) at Federal_Mogul.handlers.generaDatiTecniciPDF.CreaFilePDFDatiTecnici(DatiVeicolo dV, List`1 dati, Int32 idtipo, String clearengine, String svg, HttpContext context) in ... – Mike Vinyl May 09 '16 at 12:36

1 Answers1

0

You are most likely getting this exception because you don't have write permissions to the directory that is used to store the embedded dll. Depending on the platform you run Magick.NET on it will write a x86 or a x64 dll to a temporary directory. The location of the directory is MagickAnyCPU.CacheDirectory Setting this property to a folder where your application can write to will probably resolve the issue.

dlemstra
  • 7,813
  • 2
  • 27
  • 43