PC Review


Reply
Thread Tools Rate Thread

CustomAttribute: problem again!

 
 
julien
Guest
Posts: n/a
 
      12th Feb 2005
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
 
Reply With Quote
 
 
 
 
Joakim Karlsson
Guest
Posts: n/a
 
      12th Feb 2005
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

 
Reply With Quote
 
julien
Guest
Posts: n/a
 
      12th Feb 2005
julien wrote:
> Problem: I got "dependencies.Dependencies"


Sorry, it was: I got "AssemblyDependencies is null"

Thanks
Julien
 
Reply With Quote
 
julien
Guest
Posts: n/a
 
      13th Feb 2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with CustomAttribute in a derived class of DropDownList ryjack Microsoft ASP .NET 0 30th Jul 2006 05:54 AM
problem after problem after problem - winXP wont start! =?Utf-8?B?TWF2aXJpY2s=?= Windows XP Help 2 23rd Apr 2006 02:55 PM
How to find all classes in an assembly having a customAttribute? Sky Microsoft C# .NET 5 13th Jul 2004 11:27 AM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Hardware 2 5th Feb 2004 10:22 PM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Advanced Server 2 5th Feb 2004 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 AM.