08-27-2009 03:38 AM - edited 08-27-2009 03:42 AM
I have a test sequence that uses the .NET adapters quite a lot.
Since this test is a test on files, some of the .NET method calls accept file paths as parameters.
The .NET dll, the files I'm testing and the sequence file all reside in the same directory on the hard drive.
The file path for the dll method calls is passed via test stand by using the path data type,
and the path variable in TS contains only the file name, this way I wanted to ensure that no matter where the test is downloaded
as long as the test sequence and the tested files reside in the same directory the test should run.
When I go to test stand and open the sequence file via the File->Open and navigate to the seq file, and run the sequence everything works ok.
But when I opened a new test stand instance, and clicked on the recent files, and tried to load the sequence it blew up on me:
The instance of the .NET class could not be retrieved.
Could not find file 'D:\Program Files\National Instruments\TestStand 4.1\Name.Extension'.
Source: mscorlib at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
(...) <- more stack trace, but irrelevant to the problem
Solved! Go to Solution.
08-27-2009 02:02 PM
Maciej,
Is the path you are referring to one that you are just passing in as a parameter to your own code? What are you doing with the path?
For most Windows SDK functions and other library functions, if you use a relative path, Windows expects to find the file relative to the current working directory. The current working directory is set by the open file dialog when you browse to a specific directory and by many other things and is global to the entire process. Therefore you can't and shouldn't rely on the current working directory being set to any particular directory. If you have a path that you want to be relative to the sequence file path there are two options that I would suggest.
1) build an absolute path to your file at runtime based on the sequence file's path and your relative path. Both can be gotten programmatically at runtime via expressions or the TestStand API.
Or:
2) Use TestStand's builtin file path search directory feature, FindFile, either via the API or an expression function. By default, if pass the current sequence file parameter to FindFile it will check the current sequence file directory first before looking in the other search directories.
Hope this helps,
-Doug
08-28-2009 05:34 AM
08-28-2009 10:23 AM
TestStand does check the current sequence file directory by default for paths you specify as code module paths using the normal TestStand search directories algorithm. But in your case you aren't giving the path to any TestStand code, you are just passing the path into a Microsoft written dotnet function, System.IO.File.Exists(). TestStand has no control over how Microsoft's function treats relative paths (apparently it uses the current working directory as most Windows SDK functions do). Also, in your use case you probably don't want to use the full teststand search directories algorithm because that will check for the file in other directories besides just the current sequence file directory if it doesn't find it there so building the absolute path with the sequence file's path is probably the best thing to do in your use case.
So in summary
1) TestStand does generally look in the current sequence file directory and other search directories for relative paths that you give to TestStand.
2) You are not giving this relative path to TestStand you are giving it to Microsoft's System.IO.File.Exists() function. This function appears to assume that relative paths are relative to the current working directory.
Hope this helps clarify things,
-Doug
08-28-2009 10:52 AM
Just want to add that if you do want to look for your file using the standard TestStand search directories algorithm then you should just use the FindFile() expression function in a statement step instead of calling System.IO.File.Exists(). But I'm not sure if that's what you want in your use case.
-Doug
08-28-2009 01:03 PM
I used the RunState.SequenceFile and extracted the path property value from it.
I just stripped that property of the seqfilename with a little tiny bit of scripting, and this way I got the absolute path, and it works for me now.
The System.IO.File.FileExists() call I used in the seq file attached just show an easy .NET call, that I coud use with the pass/fail adapter, as I din't want to send pieces of my production, awesome sequence 🙂
Thanks,
Maciej