473,513 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.NullReferenceException - But just look where...


Firstly I'd like to say hello. This is my first post having ghosted for some time - I know,
I'm a bad man.

I'm pretty sure this following post hasn't been adressed on the forum, I may be wrong -
it's quite large.

Why on this earth is the following line of code causing a NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the System.Drawing
collection is messing up... but surely this is caused by something I have done. The line
I have shown you is literaly the first line of code executed in the on Page_Load
method. Nothing happens before it!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
Nov 17 '05 #1
9 1356
Oddball <jo****@SbPfAwMd.co.uk> wrote:
Why on this earth is the following line of code causing a NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the System.Drawing
collection is messing up... but surely this is caused by something I have done. The line
I have shown you is literaly the first line of code executed in the on Page_Load
method. Nothing happens before it!


My guess is that as it's a GDI+ class, ASP.NET may be having trouble
using it as a service - services don't tend to do anything with
graphic-type resources.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
That's rather bizarre. I wonder if it could be a security problem?

You could try this:
before starting your application, run this command: caspol.exe -security off

Then start your application (the command only affects applications after you
start them, so don't cheat <g>).

If you start working after that, then you at least know that you need to
look at .net security for the answer.

BTW: don't forget to run caspol.exe -security on when you are finished.
"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:jF*****************@newsfe2-win.ntli.net...

Firstly I'd like to say hello. This is my first post having ghosted for
some time - I know,
I'm a bad man.

I'm pretty sure this following post hasn't been adressed on the forum, I
may be wrong -
it's quite large.

Why on this earth is the following line of code causing a
NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the
System.Drawing
collection is messing up... but surely this is caused by something I have
done. The line
I have shown you is literaly the first line of code executed in the on
Page_Load
method. Nothing happens before it!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk

Nov 17 '05 #3

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:jF*****************@newsfe2-win.ntli.net...

Firstly I'd like to say hello. This is my first post having ghosted for
some time - I know,
I'm a bad man.

I'm pretty sure this following post hasn't been adressed on the forum, I
may be wrong -
it's quite large.

Why on this earth is the following line of code causing a
NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the
System.Drawing
collection is messing up... but surely this is caused by something I have
done. The line
I have shown you is literaly the first line of code executed in the on
Page_Load
method. Nothing happens before it!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk


Jon is right, these classes can't/shouldn't be used from web server
applications. What do you trying to achieve?

Willy.
Nov 17 '05 #4

The classes seem to work fine as I had them working a good 24 hours ago. I've finaly
worked out what's wrong. I'll get to that in a second because I have a cause not a
solution.

The aim of this code is to turn a custom font which we created into an image for
streaming to a page. The GDI+ classes are used on webpages to create things like
Thumbnails, to resize and reorientate images on the fly. If you have a database of
images you don't want to be having to store massive, large, medium, small and
thumbnail versions of every image.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote:

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:jF*****************@newsfe2-win.ntli.net...

Firstly I'd like to say hello. This is my first post having ghosted for
some time - I know,
I'm a bad man.

I'm pretty sure this following post hasn't been adressed on the forum, I
may be wrong -
it's quite large.

Why on this earth is the following line of code causing a
NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the
System.Drawing
collection is messing up... but surely this is caused by something I have
done. The line
I have shown you is literaly the first line of code executed in the on
Page_Load
method. Nothing happens before it!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk


Jon is right, these classes can't/shouldn't be used from web server
applications. What do you trying to achieve?

Willy.

------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
Nov 17 '05 #5

Right - the problem is being caused by some unsafe code that is furter down the page.
It turns out to be VERY unsafe as the program runs MOST of the way through the first
time, SOME of the way the second time and STALLS on the first line after that. What
appears to be happening is that the code I have written is destroying the .NET
framework on my PC.

Think I'll delete my unsafe code for work at a later date and replace it with a slower,
managed version.
"Oddball" <jo****@SbPfAwMd.co.uk> wrote:

Firstly I'd like to say hello. This is my first post having ghosted for some time - I know,
I'm a bad man.

I'm pretty sure this following post hasn't been adressed on the forum, I may be wrong -
it's quite large.

Why on this earth is the following line of code causing a NullReferenceException?

pfc = new PrivateFontCollection();

Here's the stack:

System.Drawing.SafeNativeMethods.GdipNewPrivateFon tCollection(IntPtr&
fontCollection) +0
System.Drawing.Text.PrivateFontCollection..ctor()
Adquiesco2.RenderFont.Page_Load(Object sender, EventArgs e) in d:\web
design\active sites\adquiesco2\renderfont.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
This has got me *confused*. It looks like some code *inside* the System.Drawing
collection is messing up... but surely this is caused by something I have done. The lineI have shown you is literaly the first line of code executed in the on Page_Load
method. Nothing happens before it!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk

------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
Nov 17 '05 #6

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:gD****************@newsfe1-win.ntli.net...

The classes seem to work fine as I had them working a good 24 hours ago.
I've finaly
worked out what's wrong. I'll get to that in a second because I have a
cause not a
solution.

The aim of this code is to turn a custom font which we created into an
image for
streaming to a page. The GDI+ classes are used on webpages to create
things like
Thumbnails, to resize and reorientate images on the fly. If you have a
database of
images you don't want to be having to store massive, large, medium, small
and
thumbnail versions of every image.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote:


The fact that they work doesnt mean they should work all the time, it
depends on the environment, normaly spoken Windows.Forms and Windows.Drawing
classes aren't meant to be used server side.
Don't say we didn't warn you if it breaks.

Willy.

Nov 17 '05 #7
He should be OK using GDI+ on the web. In fact, there are both books and
articles out there that detail the use of GDI+ for doing just what the
poster is discussing -- dynamic creation thumbnails and such.

Now, I agree that we should probably not be using anything in the
System.Windows namespace for the web, but note that the drawing namespace is
System.Drawing, not Windows.Drawing, and based on a couple of graphics books
that I have lying around here, that's intentional.
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uV**************@TK2MSFTNGP15.phx.gbl...

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:gD****************@newsfe1-win.ntli.net...

The classes seem to work fine as I had them working a good 24 hours ago.
I've finaly
worked out what's wrong. I'll get to that in a second because I have a
cause not a
solution.

The aim of this code is to turn a custom font which we created into an
image for
streaming to a page. The GDI+ classes are used on webpages to create
things like
Thumbnails, to resize and reorientate images on the fly. If you have a
database of
images you don't want to be having to store massive, large, medium, small
and
thumbnail versions of every image.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote:


The fact that they work doesnt mean they should work all the time, it
depends on the environment, normaly spoken Windows.Forms and
Windows.Drawing classes aren't meant to be used server side.
Don't say we didn't warn you if it breaks.

Willy.

Nov 17 '05 #8
No It's not OK, despite your books and articles. Following snippet if from
the latest MSDN docs for Whidbey.
<
Caution
Classes within the System.Drawing namespace are not supported for use within
a Windows or ASP.NET service. Attempting to use these classes from within
one of these application types may produce unexpected problems, such as
diminished service performance and run-time exceptions.

It's very unfortunate that it took 4 years this to be included as a
"Caution". IMO it should be classified as "DANGER", "unexpected problems"
and "run-time" exceptions is something you really don't want when running
asp.net, don't you.

Willy.
"J.Marsch" <jm*****@newsgroup.nospam> wrote in message
news:up**************@TK2MSFTNGP14.phx.gbl... He should be OK using GDI+ on the web. In fact, there are both books and
articles out there that detail the use of GDI+ for doing just what the
poster is discussing -- dynamic creation thumbnails and such.

Now, I agree that we should probably not be using anything in the
System.Windows namespace for the web, but note that the drawing namespace
is
System.Drawing, not Windows.Drawing, and based on a couple of graphics
books
that I have lying around here, that's intentional.
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uV**************@TK2MSFTNGP15.phx.gbl...

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:gD****************@newsfe1-win.ntli.net...

The classes seem to work fine as I had them working a good 24 hours ago.
I've finaly
worked out what's wrong. I'll get to that in a second because I have a
cause not a
solution.

The aim of this code is to turn a custom font which we created into an
image for
streaming to a page. The GDI+ classes are used on webpages to create
things like
Thumbnails, to resize and reorientate images on the fly. If you have a
database of
images you don't want to be having to store massive, large, medium,
small
and
thumbnail versions of every image.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote:


The fact that they work doesnt mean they should work all the time, it
depends on the environment, normaly spoken Windows.Forms and
Windows.Drawing classes aren't meant to be used server side.
Don't say we didn't warn you if it breaks.

Willy.




Nov 17 '05 #9
I stand corrected.

It is very unfortunate that it took this long for it to come out -- there
are quite a few examples out there of using these technologies together. I
haven't verified the articles yet, but there look to be serveral of them
online right now in MSDN magazine articles (search for GDI+ and ASP.net).
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
No It's not OK, despite your books and articles. Following snippet if from
the latest MSDN docs for Whidbey.
<
Caution
Classes within the System.Drawing namespace are not supported for use
within a Windows or ASP.NET service. Attempting to use these classes from
within one of these application types may produce unexpected problems,
such as diminished service performance and run-time exceptions.


It's very unfortunate that it took 4 years this to be included as a
"Caution". IMO it should be classified as "DANGER", "unexpected problems"
and "run-time" exceptions is something you really don't want when running
asp.net, don't you.

Willy.
"J.Marsch" <jm*****@newsgroup.nospam> wrote in message
news:up**************@TK2MSFTNGP14.phx.gbl...
He should be OK using GDI+ on the web. In fact, there are both books and
articles out there that detail the use of GDI+ for doing just what the
poster is discussing -- dynamic creation thumbnails and such.

Now, I agree that we should probably not be using anything in the
System.Windows namespace for the web, but note that the drawing namespace
is
System.Drawing, not Windows.Drawing, and based on a couple of graphics
books
that I have lying around here, that's intentional.
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uV**************@TK2MSFTNGP15.phx.gbl...

"Oddball" <jo****@SbPfAwMd.co.uk> wrote in message
news:gD****************@newsfe1-win.ntli.net...

The classes seem to work fine as I had them working a good 24 hours
ago.
I've finaly
worked out what's wrong. I'll get to that in a second because I have a
cause not a
solution.

The aim of this code is to turn a custom font which we created into an
image for
streaming to a page. The GDI+ classes are used on webpages to create
things like
Thumbnails, to resize and reorientate images on the fly. If you have a
database of
images you don't want to be having to store massive, large, medium,
small
and
thumbnail versions of every image.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote:
The fact that they work doesnt mean they should work all the time, it
depends on the environment, normaly spoken Windows.Forms and
Windows.Drawing classes aren't meant to be used server side.
Don't say we didn't warn you if it breaks.

Willy.



Nov 17 '05 #10

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

Similar topics

3
9094
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
0
9745
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520" AutoPostBackOnNodeMove="false" DragAndDropEnabled="true" NodeEditingEnabled="False" KeyboardEnabled="true" CssClass="TreeView" NodeCssClass="TreeNode"...
11
3719
by: Andreas Wirén | last post by:
Hi I'm a C# .NET newbie doing a minor school project but I'm getting a strange error message. 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object." As my references look I seem to be using the old framework(1.0.3705) for this, but re-referencing...
2
7635
by: Janet Heflin | last post by:
Very new in the C# world so give me a break here. I have created two web forms, one passes information to the other and brings up the data based on the passed field. When I do the updateRow I get the object recrence not set to an instance of an object. If I rem out the error message on the update it goes through and acts as though it...
2
7781
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item in treeview i display the content item in axWebBrowser, i close the sub form normally when i close the main the following error is generated An...
2
2724
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the Windows domain user account and tried to open the same page which has the databasde query code. When the two user tried to open the same page at the...
3
3640
by: Alex J. | last post by:
I just started to learn C# (my background is in C++), and right now I study the sockets, TCP/IP etc... so, I found a usefull source code at: http://www.codeguru.com/Csharp/Csharp/cs_network/sockets/article.php/c8781/. But there is a scenarion that throw a strange exception. So, the client is connected to the server, I send a message from...
1
2016
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
0
1326
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
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...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7563
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...
1
7125
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...
0
5703
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...
0
4757
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1612
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
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.