473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading Xml-File as embedded resource in DLL

Hi,
I am trying to read a XML-File which I marked as embedded resource from
within the code of my DLL. Unfortunately it doesn't work.
On my search for the error I inserted some code for outputing all
Resources names to a simple textfile. Here nothing is output.

Here my code (a little messy after about 3 hours of debugging):
// Use the LoadXml method to load the XslTransform
// object with the style sheet.
assembly = Assembly.GetCallingAssembly();

// -- Begin -- Debug code
string[] resourceNames = assembly.GetManifestResourceNames();
System.IO.StreamWriter writer =
System.IO.File.CreateText("c:\\TestFile.txt");
writer.WriteLine("Also ... ich hoffe, dass da jetzt gleich was im
Textfile steht ...");
for(int x = 0; x < resourceNames.Length; x++)
{
writer.WriteLine(resourceNames[x]);
}
writer.WriteLine("... Ende");
writer.Close();
// -- End -- Debug code

// Read the Resource and create an XmlDocument from it
s =
assembly.GetManifestResourceStream("syngo.SeSo.Eng ine.XPathResolver.xslt");
theStylesheet = new XmlDocument();
reader = new StreamReader(s);
theStylesheet.LoadXml(reader.ReadToEnd());
I have no more ideas ... please help me ...

Christofer
Nov 16 '05 #1
7 19216
SP
> I am trying to read a XML-File which I marked as embedded resource from
within the code of my DLL. Unfortunately it doesn't work.
On my search for the error I inserted some code for outputing all
Resources names to a simple textfile. Here nothing is output.

Here my code (a little messy after about 3 hours of debugging):
// Use the LoadXml method to load the XslTransform
// object with the style sheet.
assembly = Assembly.GetCallingAssembly();

// -- Begin -- Debug code
string[] resourceNames = assembly.GetManifestResourceNames();
System.IO.StreamWriter writer =
System.IO.File.CreateText("c:\\TestFile.txt");
writer.WriteLine("Also ... ich hoffe, dass da jetzt gleich was im
Textfile steht ...");
for(int x = 0; x < resourceNames.Length; x++)
{
writer.WriteLine(resourceNames[x]);
}
writer.WriteLine("... Ende");
writer.Close();
// -- End -- Debug code

// Read the Resource and create an XmlDocument from it
s =
assembly.GetManifestResourceStream("syngo.SeSo.Eng ine.XPathResolver.xslt"); theStylesheet = new XmlDocument();
reader = new StreamReader(s);
theStylesheet.LoadXml(reader.ReadToEnd());


You mention resources in a DLL but are using Assembly.GetCallingAssembly.
You should
use Assembly.GetAssembly

e.g.

string[] resourceNames =
Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames()
;
Nov 16 '05 #2
SP wrote:

You mention resources in a DLL but are using Assembly.GetCallingAssembly.
You should
use Assembly.GetAssembly

e.g.

string[] resourceNames =
Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames()
;


Unfortunately this didn't work. What would exactly be the name if I have
a class a.b.c.d.CoolClass in a dll called myCoolStuff.dll?
I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?

Chris
Nov 16 '05 #3
SP
> > You mention resources in a DLL but are using
Assembly.GetCallingAssembly.
You should
use Assembly.GetAssembly

e.g.

string[] resourceNames =
Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames() ;

Unfortunately this didn't work.


The resourceNames array is empty?

What would exactly be the name if I have a class a.b.c.d.CoolClass in a dll called myCoolStuff.dll?
What name are you referring to? The name of the resource? Lets get string[]
resourceNames =
Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames()
working first. Then this will give you the resource name.

SP
I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?


Nov 16 '05 #4
SP wrote:
You mention resources in a DLL but are using
Assembly.GetCallingAssembly.
You should
use Assembly.GetAssembly

e.g.

string[] resourceNames =

Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames()
;

Unfortunately this didn't work.

The resourceNames array is empty?

What would exactly be the name if I have
a class a.b.c.d.CoolClass in a dll called myCoolStuff.dll?

What name are you referring to? The name of the resource? Lets get string[]
resourceNames =
Assembly.GetAssembly(typeof(MyDLL.AnyClassInDLL)). GetManifestResourceNames()
working first. Then this will give you the resource name.

SP

I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?


What I meant was what do I have to put in instead of MyDLL.AnyClassInDLL
Is this jeust the simple namespace of any class within the same DLL? or
do I have to append the dll-name in some way?


Nov 16 '05 #5
SP
> >>I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?


What I meant was what do I have to put in instead of MyDLL.AnyClassInDLL
Is this jeust the simple namespace of any class within the same DLL? or
do I have to append the dll-name in some way?


It can be the name of any class in the DLL that contains the embedded
resources, it needs to be
qualified as if you were instansiating it in the exact same code block, so
it may need
to be fully qualified or might just need the name of the DLL. Your code
won't compile if
typeof(MyDLL) can not be resolved.

SP
Nov 16 '05 #6
SP wrote:
I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?


What I meant was what do I have to put in instead of MyDLL.AnyClassInDLL
Is this jeust the simple namespace of any class within the same DLL? or
do I have to append the dll-name in some way?

It can be the name of any class in the DLL that contains the embedded
resources, it needs to be
qualified as if you were instansiating it in the exact same code block, so
it may need
to be fully qualified or might just need the name of the DLL. Your code
won't compile if
typeof(MyDLL) can not be resolved.

SP


I am building a Project which is compiled into a DLL. The default
namespace of the project is "syngo.SeSo.Engine". I added an XSL-File
called "XPathResolver.xsl" as "embedded resource". This should result in
the file beeing available under the name
"syngo.SeSo.Engine.XPathResolver.xsl". Here is my code:
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;
using syngo.SeSo.Utilities;

namespace syngo.SeSo.Engine
{
internal class XPathResolver
{
/// <summary>
/// This method is used for eliminating all occurences
/// of relative XPath expressions. I also handles resolving
/// all usages of complex datatypes by calling the
/// DatatypeResolver.
/// </summary>
/// <param name="theDocument">Document containing relative XPath
expressions and complex datatypes</param>
/// <returns>Document containing only absolute XPath expressions and
simple datatypes</returns>
internal static System.Xml.XmlDocument Process(System.Xml.XmlDocument
theDocument)
{
Assembly assembly;
Stream s;
XmlDocument theStylesheet;
StreamReader reader;

// Use the LoadXml method to load the XslTransform
// object with the style sheet.
assembly = Assembly.GetAssembly(typeof(syngo.SeSo.Engine.XPat hResolver));

// -- Begin -- Debug code
string[] resourceNames = assembly.GetManifestResourceNames();
System.IO.StreamWriter writer =
System.IO.File.CreateText("c:\\TestFile.txt");
writer.WriteLine("The MainifestResourceNames are: {");
for(int x = 0; x < resourceNames.Length; x++)
{
writer.WriteLine(resourceNames[x]);
}
writer.WriteLine("}");
writer.Close();
// -- End -- Debug code

return null;
}
}
}

The resulting textfile contains not a singe ResourceName.
What am I doing wrong?
Nov 16 '05 #7
SP wrote:
I tried simply using the namespace of the class I am trying to read the
Resource with (a.b.c.d.CoolClass) but I can't see any resources :(
As far as I understood the whole resource-thing all Files are accessable
under the projects default namespace and all I have to do is set the
"Build Action" to "Embedded Resource" ... is this correct?


What I meant was what do I have to put in instead of MyDLL.AnyClassInDLL
Is this jeust the simple namespace of any class within the same DLL? or
do I have to append the dll-name in some way?

It can be the name of any class in the DLL that contains the embedded
resources, it needs to be
qualified as if you were instansiating it in the exact same code block, so
it may need
to be fully qualified or might just need the name of the DLL. Your code
won't compile if
typeof(MyDLL) can not be resolved.

SP

After trying a very long time we switched back to loading simple files,
since wa couldn't get loading from resource to work.

Thanks anyway ...
Nov 16 '05 #8

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

Similar topics

0
2191
by: Michael Alers | last post by:
Hi, I have the problem switching off the "loading of external DTD" feature while transforming xml/xslt with XALAN. The used xml-parser is XERCES. I know how to switch off this feature when only...
0
2278
by: Michael Alers | last post by:
Hello, I am extracting XML from a dbase and using jstl xml tag library to parse and display the xml. The problem I have is that the XML contains a DOCTYPE with a relative DTD declaration eg. ...
2
1691
by: Hegemony Cricket | last post by:
I'm a relative XML newbie, but it surprised me to hear that it is standard practice to have an XML document load the corresponding DTD from your company's site, e.g. <!DOCTYPE mytype SYSTEM...
1
2323
by: Nomad | last post by:
I'm trying to load an XML document into the DOM using the ActiveXObject I've succeeded in doing this on one machine. Which shouldn't becaus I've checked for the ActiveXObject and it doesn't...
5
2711
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use...
2
4475
by: Patrick J. Schouten | last post by:
I am trying to transfor an XML document prior to loading into a Dataset. My problem stems from the known bug in Visual Studio that prevents loading a well formed XML because of duplicate child...
2
2171
by: Che | last post by:
Greetings, I am writing an application that uses an extendible XML file. in order to validate that XML I use a main XSD and in additional - few more extensions XSD's that uses the types in the...
3
1401
by: Mauricio Correa L. | last post by:
Hello, i have a string with a XML inside, but when a try lo load a dataset with the next code. Dim all As String = Webservice.getName(TextName.Text, TextNo2.Text).ToString 'this webmethod return...
6
4487
by: Organza | last post by:
Good morning. Im building a little utility that load dll and show me all his properties and methods. somthing like the object browser. but i have a big problem with it. when im loading a .net...
4
2371
Soniad
by: Soniad | last post by:
Hello, i am using VBScript to load xml file and creating array of xml child nodes. i am retreiving this xml file from server using "Server.mappath". i think due to this process, my asp page is...
0
7234
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
7136
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
7412
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...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.