The type initializer for "System.Drawing.SafeNativeMethods" threw an exception

  • Thread starter Thread starter Colin
  • Start date Start date
C

Colin

Hi there,

I have wrote a simple console app in C# to get the
dimensions for a jpeg file

/***
Image img = Image.FromFile(@"C:\TEMP\PvFile\1036437.jpg",
true);
LogEvent("Height = " + img.Height.ToString() + "; Width
= " + img.Width.ToString());
****/

But when I call this console app from a SQL query
analyzer, it throws an error, says "The type initializer
for "System.Drawing.SafeNativeMethods" threw an exception."

/* The T-SQL for running this app*
DECLARE @cmd varchar(1024)
SET @cmd = 'C:\PdfExtractor\P2I.Utilities.Pdf2Text.exe'
EXEC master.dbo.xp_cmdshell @cmd
/****/

Does this has something to do with permission? Because if
I run this app from the command line, it runs OK without
error.

regards,
Colin
 
Colin said:
I have wrote a simple console app in C# to get the
dimensions for a jpeg file

/***
Image img = Image.FromFile(@"C:\TEMP\PvFile\1036437.jpg",
true);
LogEvent("Height = " + img.Height.ToString() + "; Width
= " + img.Width.ToString());
****/

But when I call this console app from a SQL query
analyzer, it throws an error, says "The type initializer
for "System.Drawing.SafeNativeMethods" threw an exception."

/* The T-SQL for running this app*
DECLARE @cmd varchar(1024)
SET @cmd = 'C:\PdfExtractor\P2I.Utilities.Pdf2Text.exe'
EXEC master.dbo.xp_cmdshell @cmd
/****/

Does this has something to do with permission? Because if
I run this app from the command line, it runs OK without
error.

My guess (and it really is a complete guess) is that the SQL process
doesn't have appropriate rights to use the graphics system. If *all*
you want to do is get the dimensions, and it'll always be a jpeg file,
I suggest you open the file manually and have a look at it. The jpeg
specifications are available in various forms at
http://www.wotsit.org/search.asp?page=5&s=graphics

- I haven't looked at them myself, but you may well be able to just
read some header information and easily get the size from that.
 
Back
Top