-1

From what I understand based on this and this, my app is running from a location that can be referred to with @"\Program Files\HHS\HHS.exe":

enter image description here

...and the file I want to access could be accessed via @"\Application\sscs\HHSetup.exe":

enter image description here

...but this code:

string clientVer = HHSUtils.GetFileVersion(@"\Application\sscs\HHSetup.exe"); 
. . .
public static string GetFileVersion(string filePath)
{
    try
    {
        const int VERSION_DEPTH = 4;
        var version = NativeFile.GetFileInfo(filePath);
        return version.Version.ToString(VERSION_DEPTH);
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}

...fails. Instead of a version number such as "3.1.4.7" (or something sensible like "0.0.0.0" as a "can't find it" value), GetFileVersion() returns "Win32Exception."

Even when I deal with that by forcing such an "oh, well" value:

if (clientVer.Contains("Exception")) 
{
    clientVer = "0.0.0.0";
}

...the subsequent call fails with "Unable to connect to the remote server"

// both serial num and clientVer have valid values now, such as "8675309" for serialNum and "0.0.0.0" for clientVer
string uri = string.Format("http://localhost:28642/api/FileTransfer/GetUpdatedHHSetup?serialNum={0}&clientVersion={1}", serNum, clientVer);
RESTfulMethods.DownloadNewerVersionOfHHSetup(uri);

...but that's another story; my question here is: Why does GetFileVersion() return "Win32Exception"? Is the path I am sending (@"\Application\sscs\HHSetup.exe") wrong, or is it something in GetFileVersion() itself?

UPDATE

Since the code is almost guaranteed good, I'm thinking the problem must be in the path I'm passing in - it's format or such. Maybe it is a permissions error, as Michael Kniffen supposes below; but if so, I don't know how to solve it. Or maybe it's a path formatting issue? I don't know; I'm more stumped than a 19th century Oregon homestead...

UPDATE 2

It seems to be a path issue; czech this out:

//string clientVer = HHSUtils.GetFileVersion(@"\Application\sscs\HHSetup.exe");
// to see if the path is the problem, try something more straightforward:
string clientVer = HHSUtils.GetFileVersion(@"\Program Files\HHS\vsd_setup.dll");

The commented out code was causing the problem.

The new code runs okay; I get a valid file version ("1.0.2268.0").

So it almost has to be either the path ("\Application" is not correct for accessing the "Internal Flash Drive" (or whatever the correct terminology is)) OR maybe the file itself - it doesn't have file version information, so that being the case might be the cause of the problem.

I'll test this by copying vsd_setup.dll beneath the sscs folder and trying this:

UPDATE 3

It was the file - the test works fine. So if a file doesn't have version information, a Win32Exception 13 is returned.

If the file being sought has version info, I get it (such as "1.0.2268.0"); if it doesn't, though, watch out below - all Dallas breaks loose!

string clientVer = HHSUtils.GetFileVersion(@"\Application\sscs\vsd_setup.dll");
Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    More than likely this is a permissions error. Try setting the file permissions on the file to "Full Access" for "Everyone" and see if it resolves your problem – Michael Kniffen Mar 07 '14 at 22:03
  • 1
    Get in the habit of **not** using try/catch until you understand what it does. – Hans Passant Mar 07 '14 at 22:04
  • Did you get your `NativeFile.GetFileInfo` call from the link below? It looks like it passes in the reason when throwing the exception. You'll need to look at the actual error code specified in the exception. http://blog.opennetcf.com/2010/09/28/getting-native-file-info-in-the-compact-framework/ – TyCobb Mar 07 '14 at 22:07
  • @HansPassant: I believe I understand try/catch well enough (not as well as you, granted). I don't see the benefit of not having it. It *is* returning the "Win32Exception" which is more info than I'd have without it, right? – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 22:10
  • Bizarrely, the Win32Exception has "gone away" with no change to the code...I still get the "Unable to connect" err msg, though. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 22:32
  • @MichaelKniffen: From Windows Explorer, I don't see this (set File Permissions") option on files on the handheld device. The file in question has for properties only "General" and "Details" tabs. "General" has "Read-only" and "Hidden" checkboxes, both of which are clear/unchecked. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 22:34
  • @TyCobb: I mean, "Yes, I did" get the code from the link you posted. How to look at the actual error code, though? – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 22:36
  • Apparently because the Win32Exception is constructed with the native error code, the `Message` should be telling you what is wrong. Can you post what the message is? I didn't see it when I looked earlier and you are returning it in your code. – TyCobb Mar 07 '14 at 23:02
  • @TyCobb: All I was getting was "Win32Exception"; that has gone away, somehow. But it still doesn't work; I don't know if that's because never the twain shall meet between Compact Framework and Web API, or what... – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:05
  • @TyCobb: To be more precise, GetFileVersion() is still failing, because clientVer is being set to "0.0.0.0", but I no longer see the "Win32Exception" message. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:13
  • Were you running your application while it was attached to your PC? If so, do you have a virus scanner? – PaulH Mar 07 '14 at 23:30
  • If you get the exception back, post the value of [Win32Exception.NativeErrorCode](http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.nativeerrorcode%28v=vs.80%29.aspx). Also, if you step through the code that @TyCobb pointed you to, how far do you get? – PaulH Mar 07 '14 at 23:33
  • @PaulH: I cannot step through the handheld code - it's running on the device. I copy the exe to the device and run it from there. It *is* attached to the PC, but doesn't run in the Visual Studio debugger. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:45
  • @PaulH: As to "post the value of Win32Exception.NativeErrorCode", do you mean like this: "return ex.Message.GetTypeCode().ToString();" or how? – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:47
  • I mean: `catch (Win32Exception ex){ return ex.NativeErrorCode; }` I'm not clear on why you can't use the VS debugger to step through this code. Can you explain? – PaulH Mar 07 '14 at 23:51
  • @PaulH: I can't step through because there is no working emulator; I have to actually run the code on the device. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:52
  • Okay...Why can't you use the Visual Studio debugger to debug the app on the device? – PaulH Mar 07 '14 at 23:53
  • @PaulH: If that's possible, I don't know how. I gave up on that months ago after trying everything possible and posting many questions here. – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:55
  • @PaulH: return ex.NativeErrorCode.ToString() returns "13" – B. Clay Shannon-B. Crow Raven Mar 07 '14 at 23:55
  • A delightfully unhepful error code. Okay, I recommend replacing the .netcf version of GetFileInfo() with the much longer one in the .netcf blog and filling it with lots of debug messages OR create a minimal version of your app that only does this one thing you're having problems with and try to reproduce it on the emulator with the debugger attached. – PaulH Mar 07 '14 at 23:59
  • Is error 13 "ERROR_INVALID_DATA" - the same as that found here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx ? – B. Clay Shannon-B. Crow Raven Mar 08 '14 at 00:01
  • @PaulH: Remember, I don't have an emulator. This code is from the Compact Framework Whisperer (ctacke), so I'm loathe to abandon it just yet. – B. Clay Shannon-B. Crow Raven Mar 08 '14 at 00:02
  • 1
    This is definitely not a permissions problem. Win CE doesn't have permissions. if your code is running, it has permissions. – ctacke Mar 08 '14 at 00:28
  • 2
    @B.ClayShannon Get your debugger working. Here's how I do it over ethernet (if you have it): http://stackoverflow.com/questions/12968547/visual-studio-can-i-debug-my-app-on-a-ce-device-over-the-network/12969064#12969064 I'm not sure what type of device you are using but you are sort of at the mercy of whether or not the OEM has included the necessary components in the windows image for debugging. Try that link though, it is easy enough. You copy several files, execute them, and then connect over ethernet with the IP – Alan Mar 08 '14 at 04:54
  • The device is a Symbol 3190; and I don't think they were very merciful. – B. Clay Shannon-B. Crow Raven Mar 10 '14 at 15:53
  • @Alan: The link you provide is "How to Connect to Windows CE Device Without ActiveSync" but I do have ActiveSync working - the device is connected to my PC, I just can't debug, as there is no emulator available for the device. – B. Clay Shannon-B. Crow Raven Mar 10 '14 at 16:04
  • 1
    @B.ClayShannon Debug over activesync on the real device. You don't need an emulator, select 'windows ce device' – Alan Mar 10 '14 at 17:46
  • Select Windows CE Device where? I'm willing to try it, but I can't see I'm optimistic - I tried several months ago for quite awhile to get it to work and, as I was unsuccessful, and the previous developers (who have written and maintained this app for years) also were never able to do it, I really doubt that it's possible in our scenario. – B. Clay Shannon-B. Crow Raven Mar 10 '14 at 18:04

1 Answers1

1

Why not start out with a simple app that you just run on the device that runs through the basics? This will tell you if it's a path problem or not. Not having a live debugger doesn't mean you should forego the debugging fundamental of "start simple".

public static void Main()
{
    var path = "\\my\\file\\path.foo";

    Console.WriteLine("Checking for file...");
    var fi = new FileInfo(path);
    if(!fi.Exists)
    {
        Console.WriteLine("File doesn't exist");
        return;
    }

    try
    {
        Console.WriteLine("Getting version...");
        const int VERSION_DEPTH = 4;
        var version = NativeFile.GetFileInfo(path);
        Console.WriteLine(version.Version.ToString());
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + return ex.Message);
    }
}
ctacke
  • 66,480
  • 18
  • 94
  • 155