NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using the .net type.GetCustomAttributes method

I have a bunch of .NET assemblies that I have used with TestStand 3.0 before.
 
Now I have updated one of my classes with a custom attribute.
 
Through a series of calls I call this function in another assembly. The parameter someClass is the class that now has attributes.
 
void SomeFunction(object someClass)
{
System.Type m_Type = someClass.GetType();
object[] myAttributes = m_Type.GetCustomAttributes(typeof(MyCustomAttribute), false); //This blows up!!
.... do some more stuff ....
}
 
Before the class got attributes everything worked fine. Now it thows an exception saying that the assembly can't be found - even though some code in that assembly has already been executed. Through a file monitoring tool I can see that it look for the assembly in the TestStand\bin directory.
 
If I copy all my assemblies to the TestStand\bin directory it works!
Unfortunately that is not an acceptable solution to my customers.
 
Can you help me,
 
/Michael
0 Kudos
Message 1 of 8
(4,056 Views)
Some additional information. If the attribute-class is defined in the same assembly as the class on which I try to getCustomAttributes() it works fine. If it is dfined in another assembly an exception is thrown.
0 Kudos
Message 2 of 8
(4,048 Views)
In the failure case, where is the Attribute-defining assembly located? It needs to be in a location where the .NET assembly loader (Fusion) can find it. In your case, it should probably be in the same directory as the assembly you are calling. This will work out naturally if you specify CopyLocal = True in the properties of the reference in your Visual Studio project. If the Attribute-defining assembly seems to be in a location that Fusion should know about, you can use the Assembly Binding Log Viewer tool (fuslogvw.exe) to see what is going wrong. 
 
I tried this out and things worked for me. I attached the project and sequence file that I used. You should be able to unzip the project file and open TestGetAttributes31.seq and see it working.
 
Let me know if the attached project works for you. I used TestStand 3.1; let me know if you need a 3.0 version of the sequence.
 
If this doesn't get you to a resolution, could you either modify my project to get it to fail as yours fails or post a stripped-down version of your project so that I can reproduce the failure?
0 Kudos
Message 3 of 8
(4,039 Views)

Hi,

 

Thanks for your answer. All the assemblies are located in the same directory, and there is no problem accessing the assembly through normal function-calls. That is why it is so weird...

I would very much like to have a 3.0 version of the sequence. Then I will try to reproduce the error.

 

thanks,

Michael

0 Kudos
Message 4 of 8
(4,031 Views)

Michael -

I have attached a 3.0 version of the sequence. I don't have TestStand 3.0 installed, so I haven't tested this version of the sequence file. You might have to modify it to get it to work.

- David

0 Kudos
Message 5 of 8
(4,025 Views)
HI,
 
Your example works fine here, but it is not completely the same as my setup.
 
I made an example myself, which unfortunately also works fine.
 
I have attached my project anyway, so you can see under which circumstances we see the problem. (TestStand sequence is in the bin/debug directory).
 
/Michael
0 Kudos
Message 6 of 8
(4,011 Views)
Have you made any headway on this issue? I looked at your sequence and code and didn't see anything odd. Have you tried looking at the fuslogvw log files in the failure case?
0 Kudos
Message 7 of 8
(3,904 Views)
No, I hacked my code to make it work for now, but I do have to get back to this.
 
br,
Michael
0 Kudos
Message 8 of 8
(3,879 Views)