[Mono-list] ResourceManager

Kornél Pál kornelpal at hotmail.com
Thu Nov 17 04:20:24 EST 2005


Hi,

> I embedded a file as a resource. The name of the resource is
> sample.MediaInfoDB.sql

> But then, I cannot access it:
>
> ResourceManager rm = new ResourceManager("sample",
> Assembly.GetExecutingAssembly());

Of course you cannot access it because as you said previously it's named
"sample.MediaInfoDB.sql" rather than just "sample".:)

> Object file = rm.GetObject("MediaInfoDB.sql"); // same issue with
> sample.MediaInfoDB.sql

I think that "sample.MediaInfoDB.sql" is a plain text file. You cannot
access it using ResourceManager. ResourceManager is intended to handle
.resource files that can be created from .resx files for example using
resgen.exe. .resource files can contain any arbitary string, data and even
serialized objects but you have to use .resource files in this case. And
note that I mean the format of .resource files not just the extension.

If you want to use your current "sample.MediaInfoDB.sql" you have to use

this.GetType().Assembly.GetManifestResourceStream("sample.MediaInfoDB.sql");

that returns a System.IO.Stream and can be read using System.IO.StreamReader
for example.

Kornél

----- Original Message -----
From: "Julien Sobrier" <julien at sobrier.net>
Cc: <mono-list at lists.ximian.com>
Sent: Thursday, November 17, 2005 5:52 AM
Subject: Re: [Mono-list] ResourceManager


> Kornél Pál wrote:
>> I suggest however to use the constructor that takes a string (resource
>> name)
>> and an assembly (that contains the resource).
>>
>> Kornél
>
> Thank you.
>
> I've made some progress, but I still have some issues.
>
> I embedded a file as a resource. The name of the resource is
> sample.MediaInfoDB.sql
>
> I checked the name using this code:
>
> // Get this type's assembly
> Assembly assem = this.GetType().Assembly;
>
> // Enumerate the assembly's manifest resources
> foreach (string resourceName in assem.GetManifestResourceNames())
> {
>    Console.WriteLine("resource: " + resourceName);
> }
>
> It displays: "resource: sample.MediaInfoDB.sql"
>
>
> But then, I cannot access it:
>
> ResourceManager rm = new ResourceManager("sample",
> Assembly.GetExecutingAssembly());
>
> Object file = rm.GetObject("MediaInfoDB.sql"); // same issue with
> sample.MediaInfoDB.sql
>
> At runtime, the method GetObject returns the exception
> MissingManifestResurceException: Could not find any resource appropriate
> for the specified culture or its parents. Make sure "sample.resources"
> was correctly embedded or linked into assembly "Database".
>
> Any idea why it is failing?
>
>
> Thank you
> Julien
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>



More information about the Mono-list mailing list