CustomAttribute: problem again!

J

julien

Hello,
I'm sorry to send another message about the custom assemblies. The
examples I find online don't help to find out what is wrong in my file.

In a dll:
[assembly:AssemblyDependencies( "ee","1.0.0.0","aa", "1.0.0.0")]

This custom attribute:
[AttributeUsage(AttributeTargets.Assembly)]
public class AssemblyDependencies : Attribute
{
public Hashtable Dependencies;

public AssemblyDependencies(params string[] dependencies)
{
Dependencies = new Hashtable();

if (dependencies.Length % 2 == 0)
{
for(int count = 0; count < dependencies.Length; count += 2)
{
try
{
this.Dependencies.Add(dependencies[count], new
Version(dependencies[count+1]));
}
catch(Exception e)
{
Console.WriteLine("Error");
}
}
}
}
}


Then, in another program, I load this dll:
Assembly asm = Assembly.LoadFrom(this.fullName);

Attribute[] attributes;
try
{
attributes = Attribute.GetCustomAttributes(asm);
}
catch(Exception e)
{
Console.WriteLine("Error");
}

foreach(Attribute attribute in attributes)
{
AssemblyDependencies dependencies = attribute as
AssemblyDependencies;

if (dependencies != null)
{
try
{
Console.WriteLine("{0}", dependencies.Dependencies);
}
catch(Exception e)
{
Console.WriteLine("Error");
}
}
else
Console.WriteLine("{0} is null", attribute);
}
}


Problem: I got "dependencies.Dependencies"

When I do the samething for System.Reflection.AssemblyTitleAttribute, it
works fine.

The path of the dll is correct, the dependencies are also correctly
added in AssemblyDependencies.

Thank you
Julien
 
J

Joakim Karlsson

I would guess your output would be something like
"System.Collections.Hashtable".

The Dependencies field is a Hashtable. Console.WriteLine simply calls
the ToString method on the Hashtable and routes the result to the console.

Replace

Console.WriteLine("{0}", dependencies.Dependencies);

with something like this

foreach(string s in dependencies.Dependencies.Keys)
{
Console.WriteLine("{0} {1}", s, dependencies.Dependencies);
}

BTW, your attribute should be called AssemblyDependenciesAttribute.

Regards,
Joakim
 
J

julien

And here are the information I got about plugin.dll:

..assembly extern mscorlib
{
.ver 1:0:5000:0
}
..assembly 'Plugin'
{
.custom instance void class
[mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = (
01 00 18 4A 75 6C 69 65 6E 53 6F 62 72 69 65 72 //
....JulienSobrier
46 69 72 73 74 50 6C 75 67 69 6E 00 00 ) //
FirstPlugin..

.custom instance void class AssemblyDependencies::.ctor(string[]) = (
01 00 04 00 00 00 02 65 65 07 31 2E 30 2E 30 2E //
........ee.1.0.0.
30 02 61 61 07 31 2E 30 2E 30 2E 30 00 00 ) //
0.aa.1.0.0.0..

.hash algorithm 0x00008004
.ver 0:1:1:1
}


SO, the only difference I see between AssemblyTitleAttribute (that
works) and AssemblyDependencies (yhat doesn't work) is [mscorlib]. What
is this?

Thank you
Julien
 

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