Object reference not set to an instance of an object

  • Thread starter Thread starter julien
  • Start date Start date
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
 
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
 
Back
Top