473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

'embedded resources' and Dispose error..?

Hello,

I'm using Visual C# 2005 Express.
if I create a new "application windows" project and run it (F5), it works
well. (an empty window is launched..)

as soon as I set the build action to embedded resource, I can't run it
anymore because I got an error on
'WindowsApplication1.Form1.Dispose(bool)'..

I find several examples online about embedded resource, but nothing that
give me an explanation on what I should do about that.
I'm beginning with C#, so I surely missed something, but I already search
for a moment without finding a solution, so if someone could help me a
little, it would be nice.

thanks.
Fred

Sep 8 '07 #1
8 2435
*what* are you setting as "embedded resource"? Form1.cs? What are you
trying to do? Basically, don't change this. You /do/ want to compile
this file, so leave it as "Compile" Embedded resource means that the
file is dumped (verbatim) into the assembly as a resource, useful for
including support files (xml, graphics, etc) with the app without
needing to deploy these files separately. But this is not how you
treat code, unless you genuinely intend to bundle the source file with
the app (instead of compiling it). Which would be rare.

By defualt, forms in VS (and express) use "partial classes"; this
means that there is a second file (Form1.Designer.cs) that is part of
the same class. But by changing the build action, the only file it can
find (for the Form1 class) is Form1.Designer.cs - which doesn't
explicitely know that it is a Form (this is part of Form1.cs), and
hence has no Dispose(bool) method to override.

Marc
Sep 8 '07 #2
OK, thanks.. but of course my example was just to give you the most simple
way to reproduce my problem (in case it was needed..).
but of course my real program is bigger than that and yes I have support
files (graphics) that I want to include.

so your answer seems to explain me why the examples I found online didn't
have this problem, because they was made with VS 2003 and there wasn't an
external Form1.designer.cs. that was simple example in only one file.

well, now, how can I make it go with "partial classes" if I set the build
action to embedded resource..?

thanks.
Fred


Sep 8 '07 #3
sorry, English is not my mother language and I think I replied a little too
fast, without reading what I wrote.. should have been clearer.
thanks again.
Fred
Sep 8 '07 #4
well, now, how can I make it go with "partial classes" if I set the build
action to embedded resource..?
Please can you explain *why* you want to set it as an embedded
resource? Basically, I'm pretty sure that this isn't going to do what
you think it is... so tell us what actually want to do, and we might
be able to suggest the right way to achieve it.

Marc

Sep 9 '07 #5
Hello,
what I want to do is having only one file, with my different small images
embedded within and be able to access thoses images for my software.

since I see different examples doing that, like those two :
http://www.devhood.com/tutorials/tut...tutorial_id=75
http://support.microsoft.com/kb/319292/en-us

I tried to make something similar, but there wasn't "partial classes" in
those examples.
but as you said, maybe there's now another way to do that..

Thanks again.
Fred
Sep 9 '07 #6
It is perfectly possible to add images; first, however, you need to
get the images into the project. Using Visual Studio (including
"express") you can drag files from Explorer into the solution explorer
(the tree with the files). Once the images are in the solution, there
are 2 ways to get access to them (in both cases, leave the build
action of the form as "compile")

The easiest option is to set the build action of the image(s) to
"content" (the default), and add a resource file (there may already by
one called Resources.resx) in the Properties folder. Open the resource
file (View Designer), and drag the image from the solution explorer
into the resource designer (anywhere... it doesn't matter). This tells
the compiler to embed the image into the resource file, which itself
will be embedded into the exe. You can now access the image by name,
simply by looking at ResourceFileName.ImageFileName - i.e. for me my
resource file is "Resources.resx", and my image is "Test.jpg", so I
can use Resources.Test (which is an Image). Using the same example, if
it doesn't compile (The name 'Resources' does not exist in the current
context) then right-click on the Resources (underlined in blue in the
editor), Resolve -using [some namespace]. It should then work. Your
images should also now appear automatically when selecting button
images etc.

The second option is to change the build action of the image(s) to
"embedded resource"; however, it is trickier to get hold of these -
you need to use Assembly.GetManifestResourceStream({name}), and
process the stream manually.

Sep 9 '07 #7
Wow, I'm sorry, I think I got it.. I'm not near my PC with my C# project,
but it seems so evident to me just now, that it's a pity I didn't think of
it yesterday.
well I set the "embedded resource" build action to my Form1.cs, but I just
need to set this to the graphic files I need to embed, not to my Form..

many thanks again and sorry to eat your time for a so stupid error of mine..
Fred.
Sep 9 '07 #8
yes, with the resx file is really easy for what I need yet..
big thanks.
Fred
Sep 9 '07 #9

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

Similar topics

13
by: Alexander May | last post by:
Hi, I love Python! I've been using it for a couple of years now and have found it to be a highly productive language. I evangelize it to my developer friends and am probably responsible for...
3
by: Saradhi | last post by:
How to get the names of all the Resources embedded in a Resource File? -SARADHI
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
4
by: Jon Rista | last post by:
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm...
4
by: PromisedOyster | last post by:
There are various contradictory newsgroup postings on this issue, but I would really like a definitive answer from the .NET gurus out there? We have various WinForms that contain multiple Icons...
25
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class...
8
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx...
2
by: steve | last post by:
I have the following routine for retrieving error message strigs from a resource file which is embedded in the project. But when it is called I get the error messsage "Could not find any...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.