Object reference not set to an instance of an object

J

julien

Hello,
I got the error "Object reference not set to an instance of an object"
in this piece of code:

Assembly asm = Assembly.LoadFrom(location);
System.Attribute[] attributes = Attribute.GetCustomAttributes(asm);

I checked:
* location: this is the full path + file name of a dll
* asm is not null. asm.GetName().Version gives me the correct version

I don't see what is going wrong.

Thank you
Julien
 
N

Nick Malik [Microsoft]

Hello Julien,

I would guess the following:
If the first line fails, the object isn't set when it becomes a parameter to
the second line.

e.g.
Assembly asm = Assembly.LoadFrom(location);
this line didn't find the file.

Therefore, asm is null.

Therefore:
System.Attribute[] attributes = Attribute.GetCustomAttributes(asm);

produces an error.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
julien said:
Hello,
I got the error "Object reference not set to an instance of an object" in
this piece of code:

Assembly asm = Assembly.LoadFrom(location);
System.Attribute[] attributes = Attribute.GetCustomAttributes(asm);

I checked:
* location: this is the full path + file name of a dll
* asm is not null. asm.GetName().Version gives me the correct version

I don't see what is going wrong.

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