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

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
 
J

Jon Skeet

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top