473,856 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The type initializer for "System.Drawing .SafeNativeMeth ods" threw an exception

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\PvFil e\1036437.jpg",
true);
LogEvent("Heigh t = " + img.Height.ToSt ring() + "; Width
= " + img.Width.ToStr ing());
****/

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

/* The T-SQL for running this app*
DECLARE @cmd varchar(1024)
SET @cmd = 'C:\PdfExtracto r\P2I.Utilities .Pdf2Text.exe'
EXEC master.dbo.xp_c mdshell @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
Nov 15 '05 #1
1 4321
Colin <tf****@p2ionli ne.com> wrote:
I have wrote a simple console app in C# to get the
dimensions for a jpeg file

/***
Image img = Image.FromFile( @"C:\TEMP\PvFil e\1036437.jpg",
true);
LogEvent("Heigh t = " + img.Height.ToSt ring() + "; Width
= " + img.Width.ToStr ing());
****/

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

/* The T-SQL for running this app*
DECLARE @cmd varchar(1024)
SET @cmd = 'C:\PdfExtracto r\P2I.Utilities .Pdf2Text.exe'
EXEC master.dbo.xp_c mdshell @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.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
6
17993
by: Selen | last post by:
I am using asp.net c#...I am adding a field to cystal report but I get error Exception of type System.Exception was thrown. How can I solve this error...When I insert a field from another table I dont get error... Thanks...
3
2479
by: cristiank | last post by:
hi everybody, I need to clear something out, does anybody have ever encountered such an exception until now : "Un unhandled exception of type System.NullReferenceException occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object." I receive this exception when I use HelpProvider and play a little with the question mark upon different controls.
0
1404
by: Selen | last post by:
I am using asp.net c#...I am adding a field to crystal report but I get error Exception of type System.Exception was thrown. How can I solve this error...When I insert a field from another table I dont get error... Thanks...
1
1792
by: chintu rana via DotNetMonster.com | last post by:
An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll Additional information: Overflow or underflow in the arithmetic operation. if i run vb.net application with only form no any controls at that time there is no error . But if i put first control (command button or label or textbox ) and run application then error generated at control name.
0
8539
by: Nikhil Khade | last post by:
Hello, After around 3 months, I reopened a old VB.NET solutions which used to work (and build) without any errors. Just to test it again, I build it again and it completed, without any errors, but then immediately started showing me the message "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll" at InitializeComponent() with all lines containing Image load or default icon, like the following: ...
5
4372
by: hzgt9b | last post by:
I'm building a dataset that writes out a Point type value. Here's the code that I've got: 1 Dim dsContent As DataSet = New DataSet("content") 2 Dim dtAsset As DataTable = New DataTable("asset") 3 Dim dcPk(0) As DataColumn 4 dcPk(0) = _ 5 dtAsset.Columns.Add("fullName", Type.GetType("System.String")) 6 dtAsset.Columns.Add("videoLocation", Type.GetType("System.Drawing.Point"))
4
15031
by: John Dalberg | last post by:
I am looking at a problem which is preventing my code to get a reference to any asp control inside a div section which has a runat=server attribute. This can be reproduced in a simple test: Create a blank webform and add this html inside the <formsection: <div id="myDiv" runat=server> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> In the code behind, add this code in the page_load event handler:
1
3718
by: danfoss | last post by:
Hi, I programmed the following managed C++ code, but it cannot be compiled. error C3699: '*': cannot use this indirection on type 'System::Exception'. Can somebody tell me why? Thanks. #include "stdafx.h" #include "LoadMappingTool.h" using namespace Mapping;
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10772
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9527
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4169
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.