PC Review


Reply
Thread Tools Rate Thread

Trouble with strongly-typed Image resources at design-time

 
 
Jared
Guest
Posts: n/a
 
      2nd Jan 2008
I'm working on a custom control in VS2005, and I'm experiencing a
problem using Image resources from the Resource Manager. My control
has a child collection, and each child has an Image property. My
solution has two projects, one for the control and one for the test
app using the control. I can successfully set and persist the Image
property, and all works fine at runtime and design-time.

However, *once I rebuild the control project* my control breaks in the
using project at design-time with the error "The control (my control)
has thrown an unhandled exception in the designer and has been
disabled". It references a line in my code where I access the Image
property of a child, and it appears the Image is no longer valid.

I do not have this problem if I set the Image property directly -- I
only have a problem when using a strongly-typed Image from the
Resource Manager.

I thought it might be a problem with disposing the Image objects, but
commenting that out didn't resolve the issue.

Does anyone have any tips for the correct usage of strongly-typed
Image resources in custom controls?

TIA
Jared
 
Reply With Quote
 
 
 
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      3rd Jan 2008
You may be suffering from versioning problems. Remove all asterisks from the
version tags in the AssemblyInfo file.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"Jared" <(E-Mail Removed)> wrote in message
news:3f952a86-e639-440a-a668-(E-Mail Removed)...
> I'm working on a custom control in VS2005, and I'm experiencing a
> problem using Image resources from the Resource Manager. My control
> has a child collection, and each child has an Image property. My
> solution has two projects, one for the control and one for the test
> app using the control. I can successfully set and persist the Image
> property, and all works fine at runtime and design-time.
>
> However, *once I rebuild the control project* my control breaks in the
> using project at design-time with the error "The control (my control)
> has thrown an unhandled exception in the designer and has been
> disabled". It references a line in my code where I access the Image
> property of a child, and it appears the Image is no longer valid.
>
> I do not have this problem if I set the Image property directly -- I
> only have a problem when using a strongly-typed Image from the
> Resource Manager.
>
> I thought it might be a problem with disposing the Image objects, but
> commenting that out didn't resolve the issue.
>
> Does anyone have any tips for the correct usage of strongly-typed
> Image resources in custom controls?
>
> TIA
> Jared


 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      3rd Jan 2008
On Jan 3, 8:05*am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.net>
wrote:
> You may be suffering from versioning problems. Remove all asterisks from the
> version tags in the AssemblyInfo file.
>
> --
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consultinghttp://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
> "Jared" <goo...@tripletreesoftware.com> wrote in message
>
> news:3f952a86-e639-440a-a668-(E-Mail Removed)...
>
>
>
> > I'm working on a custom control in VS2005, and I'm experiencing a
> > problem using Image resources from the Resource Manager. *My control
> > has a child collection, and each child has an Image property. *My
> > solution has two projects, one for the control and one for the test
> > app using the control. *I can successfully set and persist the Image
> > property, and all works fine at runtime and design-time.

>
> > However, *once I rebuild the control project* my control breaks in the
> > using project at design-time with the error "The control (my control)
> > has thrown an unhandled exception in the designer and has been
> > disabled". *It references a line in my code where I access the Image
> > property of a child, and it appears the Image is no longer valid.

>
> > I do not have this problem if I set the Image property directly -- I
> > only have a problem when using a strongly-typed Image from the
> > Resource Manager.

>
> > I thought it might be a problem with disposing the Image objects, but
> > commenting that out didn't resolve the issue.

>
> > Does anyone have any tips for the correct usage of strongly-typed
> > Image resources in custom controls?

>
> > TIA
> > Jared- Hide quoted text -

>
> - Show quoted text -


Thanks for the reply Bob. I tried removing the asterisks, but the
problem persisted. I'm certain this has something to do with me
disposing the Image objects incorrectly because it works fine when I
remove my disposing code. For example, my Image property on the child
control (which derives from Component) is:

public Image Graphic
{
get
{
return _Graphic;
}
set
{
if (!this.DesignMode)
{
// Dispose any previous graphic
if (null != _Graphic)
{
_Graphic.Dispose();
_Graphic = null;
}
}

_Graphic = value;

// Notify the container to redraw
if (null != this.TaskPanel)
{
this.TaskPanel.Invalidate();
}
}
}

If I comment out the check for DesignMode, the control will start
breaking in the using project when I rebuild the control project. I
assume this is because I'm disposing resources held by the Resource
Manager in the using app. I also assume that I should be disposing
the Image objects explicitly at runtime as shown in my code above.

Hopefully this makes sense. Please let me know if you have any more
insight into this behavior. Cheers!
 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      3rd Jan 2008
On Jan 3, 10:01*am, Jared <goo...@tripletreesoftware.com> wrote:
> On Jan 3, 8:05*am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.net>
> wrote:
>
>
>
>
>
> > You may be suffering from versioning problems. Remove all asterisks fromthe
> > version tags in the AssemblyInfo file.

>
> > --
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing

>
> > Ramuseco Limited .NET consultinghttp://www.ramuseco.com

>
> > Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm

>
> > Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm

>
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.

>
> > "Jared" <goo...@tripletreesoftware.com> wrote in message

>
> >news:3f952a86-e639-440a-a668-(E-Mail Removed)...

>
> > > I'm working on a custom control in VS2005, and I'm experiencing a
> > > problem using Image resources from the Resource Manager. *My control
> > > has a child collection, and each child has an Image property. *My
> > > solution has two projects, one for the control and one for the test
> > > app using the control. *I can successfully set and persist the Image
> > > property, and all works fine at runtime and design-time.

>
> > > However, *once I rebuild the control project* my control breaks in the
> > > using project at design-time with the error "The control (my control)
> > > has thrown an unhandled exception in the designer and has been
> > > disabled". *It references a line in my code where I access the Image
> > > property of a child, and it appears the Image is no longer valid.

>
> > > I do not have this problem if I set the Image property directly -- I
> > > only have a problem when using a strongly-typed Image from the
> > > Resource Manager.

>
> > > I thought it might be a problem with disposing the Image objects, but
> > > commenting that out didn't resolve the issue.

>
> > > Does anyone have any tips for the correct usage of strongly-typed
> > > Image resources in custom controls?

>
> > > TIA
> > > Jared- Hide quoted text -

>
> > - Show quoted text -

>
> Thanks for the reply Bob. *I tried removing the asterisks, but the
> problem persisted. *I'm certain this has something to do with me
> disposing the Image objects incorrectly because it works fine when I
> remove my disposing code. *For example, my Image property on the child
> control (which derives from Component) is:
>
> public Image Graphic
> {
> * *get
> * *{
> * * * return _Graphic;
> * *}
> * *set
> * *{
> * * * if (!this.DesignMode)
> * * * {
> * * * * *// Dispose any previous graphic
> * * * * *if (null != _Graphic)
> * * * * *{
> * * * * * * _Graphic.Dispose();
> * * * * * * _Graphic = null;
> * * * * *}
> * * * }
>
> * * * _Graphic = value;
>
> * * * // Notify the container to redraw
> * * * if (null != this.TaskPanel)
> * * * {
> * * * * *this.TaskPanel.Invalidate();
> * * * }
> * *}
>
> }
>
> If I comment out the check for DesignMode, the control will start
> breaking in the using project when I rebuild the control project. *I
> assume this is because I'm disposing resources held by the Resource
> Manager in the using app. *I also assume that I should be disposing
> the Image objects explicitly at runtime as shown in my code above.
>
> Hopefully this makes sense. *Please let me know if you have any more
> insight into this behavior. *Cheers!- Hide quoted text -
>
> - Show quoted text -


I think I ended up outsmarting myself while trying to create a custom
control that didn't leak memory. My control shouldn't be disposing
resources that it didn't create, so I'll just remove my code that's
disposing the Image object. =)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strongly typed resources and external assembly resx files in web a MattM Microsoft ASP .NET 0 12th Sep 2008 02:03 PM
Strongly Typed Dataset with Image Data heath Microsoft VB .NET 1 3rd Apr 2008 06:57 AM
Trouble creating strongly-typed DataTables in VS 2005 tapdsp@gmail.com Microsoft ADO .NET 0 21st Jun 2007 07:16 PM
Strongly typed resources Robert Kozak Microsoft C# .NET 0 16th Nov 2005 06:13 PM
OO Design Question - Strongly typed ArrayList Bill Cohagan Microsoft Dot NET 4 2nd Jul 2003 02:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:04 PM.