John Dunn wrote:
> Laurent Bugnion wrote:
>> Are you using 2.0?
>> If so, try the following method:
>> Assembly oAssembly = Assembly.GetAssembly( tyResourceType );
>> Stream stmInput
>> = oAssembly.GetManifestResourceStream( strPathInResource );
>> Note that the path in resources starts with the assembly's name, and
>> uses '.' instead of the usual '\' or '/', so for example if your XAML
>> file is placed in a folder named "Xaml", the full path is (for example):
>> Best way to find out what is the path of your resources is to
>> Assembly.GetManifestResourceNames in debug mode, and to check all the
>> resources' names.
> Thanks for the reply-
> I'm using 3.0.
Oh, duh *LOL* Answering to a post in the WPF newsgroup, this should be
obvious to me. Sorry. I spend too much time in the ASP.NET and C# NGs ;-)
> I tried iterating the Resource names - only 1 resource
> was shown even though I have 2 files added to my resx file. It returned
> 'db.test_resource.resources' where db is my app name and test_resources
> is my resource file name. I'm not sure where it got the final resources
> string from. I also tried iterating GetModules ( only returned db.exe )
> and GetFiles ( returned path_to_exe\db.exe ) without any luck.
I suspect that you add the files to the RESX file the old (1.1) way.
To add a file to resources in the 2.0 (and 3.0) way, you do as follow:
1) Add the XAML file to your project, using "Add existing file". The
file may be in a folder too, that's OK.
2) Select the file, select Properties (F4)
3) Set "Build action" to "Embedded resource"
Voilą. Next time you compile, the file will be added to the DLL without
you having to fiddle with the RESX file. Neat ;-)
After this, it should occur in the Resource names as standalone.
> The relevant portion of the resx file looks like this
> <data name="window_close_button" type="System.Resources.ResXFileRef,
> <value>res\window_close_button.xaml;System.String, mscorlib,
> Version=126.96.36.199, Culture=neutral,
Yes. Use the other way described above, it's easier and will act as
> The only other thing that may be an issue is that I'm calling
> Assembly::GetExecutingAssembly() to get the Assembly. That seemed to
> work when I needed an Assembly to pass into the ResourceManager
> constructor. If I need to call GetAssembly I'm not sure what type to
> pass into that call.
GetExecutingAssembly() will return the current assembly, which is
probably fine for that you do. My code is generic, I use it in a Utility
class to extract resources embedded in any assembly, which I identify
using a type present in that assembly.
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Support children in Calcutta: http://www.calcutta-espoir.ch