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[s]);
}
BTW, your attribute should be called AssemblyDependenciesAttribute.
Regards,
Joakim
julien wrote:
> 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
|