Embedded Resource File in Code Library called from ASP.Net web pag

J

Jay Pondy

I have a class library project that is being used in an ASP.Net web site.

In the library class I have several files containing SQL statements (in a
sql subdirectory) with their 'Build Action' property set to Embedded Resource.

I use the following code to retrieve the SQL statements from these embedded
resources at runtime:

protected string SQLFetch(string fileName)
{
Assembly assembly = Assembly.GetEntryAssembly();

Trace.Assert(assembly != null);

string assemblyName = assembly.GetName().Name;
string resourceName = string.Format("{0}.sql.{1}", assemblyName, fileName);
// Assembly.directory.filename

Trace.Assert(resourceName != null);

Stream stream = assembly.GetManifestResourceStream(resourceName);
string sql = string.Empty;

if (stream == null)
throw new ApplicationException(string.Format("Missing resource '{0}'.",
resourceName));
else
{
using (StreamReader rdr = new StreamReader(stream))
{
sql = rdr.ReadToEnd();
}
return sql;
}
}

When I attempt to call into this library from an ASP.Net web site the
assembly is being returned as NULL.

What do I need to do to either correct this problem or work around it?
 
J

Jay Pondy

Do it this way:

JobItems junk = new JobItems();

Assembly assembly = Assembly.GetAssembly(junk.GetType());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top