C# Assemblies question.

W

Wesley Varela

C# Assemblies question.

I have a project that writes out objects as an XML document in a specific
manner that my bosses want to use. I call this project XMLObjectIO . this
project is compiled to an DLL and referenced in the main work project.
Writing and reading primitive types goes off with out a hitch but it an
object contains an object that was written out reconstituting the object is
giving me issues.

The object is written out like this

public void WriteObject(string name, IWriteXML obj)
{
this.WriteStartElement(name);
this.WriteAttributeString("Type", obj.GetType().ToString());

obj.WriteXML(this);
this.WriteEndElement();
}

it writes the start element the attribute string that defines its type and
then writes itself then closes the element. (this works fine)

Reading it in is the problems when I pass the name to look for it finds it
quickly and gets the type that was written out.

string objectType = nav.GetAttribute("Type", "");
System.Type objType = System.Type.GetType(objectType);
objGeneric = Activator.CreateInstance(objType);
IReadXML read = (IReadXML) objGeneric;

Is then called to create an instance of the object and it then reads itself
in. however I get a null from Activator.CreateInstance(objType); saying it
is not in the assembly. I am assuming that this is referring to the DLL's
assembly.

I am looking for a way to access the types of one or possible more projects
the are in the solution. Any Ideas?
 
E

Ed Courtenay

try using something like this:

public void WriteObject(string name, IWriteXML obj)
{
this.WriteStartElement(name);
this.WriteAttributeString("Type",
obj.GetType().AssemblyQualifiedName.ToString());

obj.WriteXML(this);
this.WriteEndElement();
}
 
W

Wesman

Thanks, works perfectly


Ed Courtenay said:
try using something like this:

public void WriteObject(string name, IWriteXML obj)
{
this.WriteStartElement(name);
this.WriteAttributeString("Type",
obj.GetType().AssemblyQualifiedName.ToString());

obj.WriteXML(this);
this.WriteEndElement();
}
 

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