0

I have trouble opening a photo (with whatever Windows associated program) in my WPF app. The code:

            try
            {
                Process.Start(@"‪D:\temp\demo.jpg");
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }

Produces an exception of: "Failed to convert resource into object." 100% of the time. Inner exception: null Hresult: -2146233079

I have made sure the file and an association exists Also tried both options of "StartInfo.UseShellExecute"

Any Ideas?

user3104076
  • 41
  • 1
  • 5
  • https://stackoverflow.com/questions/7888871/hyperlink-keeps-failing? – Wiktor Zychla Apr 14 '18 at 18:31
  • Thanks for the reference. I've read it before. Adding "e.handled = true;" that worked then don't work for me. I am using VS 2017 on Windows 10 if it makes a difference. – user3104076 Apr 14 '18 at 19:26
  • Assign the image file path to your `StartInfo.FileName = "@"‪D:\temp\demo.jpg"` property. Use `StartInfo.ShellExecute = true;`, `StartInfo.CreateNoWindow = true;` – Jimi Apr 14 '18 at 20:10
  • With this correction: Process.Start(new ProcessStartInfo { FileName = @"‪D:\temp\demo.jpg", UseShellExecute = true, CreateNoWindow = true, } ); Still: "Failed to convert resource into object." – user3104076 Apr 14 '18 at 21:11
  • You mean `Process process = new Process { StartInfo = [ProcessStartInfo] };` `process.Start();` – Jimi Apr 15 '18 at 00:05
  • The path contains an invalid character ([U+202A](https://www.fileformat.info/info/unicode/char/202a/index.htm)) at the first position. If you retype the path, your code should work. – Clemens Apr 15 '18 at 08:21
  • Manually retyped and reverified path exists. Code below. Exception remains. As soon as "Process.Start()" hits: "Failed to convert resource into object.". Anyone can share a working snippet alternative for opening a jpg in its own external associated program in WPF? – user3104076 Apr 15 '18 at 15:06
  • ProcessStartInfo MyProcessStartInfo = new ProcessStartInfo { FileName = @"‪d:\temp\demo.jpg", UseShellExecute = true, CreateNoWindow = true, }; Process MyProcess = new Process { StartInfo = MyProcessStartInfo }; MyProcess.Start(); – user3104076 Apr 15 '18 at 15:09
  • If you paste `d:\temp\demo.jpg` in your system cmd.run window, what happens? What program is opening that jpg file? You could also get the opener with `AssocQueryString()` (search SO for this) and use it as the `FileName` property in your `ProcessStartInfo`, where the `Arguments` property becomes @"‪d:\temp\demo.jpg" – Jimi Apr 15 '18 at 16:14
  • Pasting the full path to the Start -> Run opens up the file in Picasa Photo Viewer right away. This piece of code worked perfectly in former (VS2015 .Net 4.5) version. Anything to do with that? – user3104076 Apr 15 '18 at 17:03
  • The simplest of all tests is `Process.Start(@"[Full Path To Picasa .exe]", @"[Full Path To JPG File]");`. If it's not working (it should, it's the same thing as cmd.run), then there's something missing in your description of the problem. The HResult you're reporting is `COR_E_INVALIDOPERATION = 0x80131509`. It's a generic System.Exception. In my experience, it usually the result of an access denied for a resource or the resource is not reachable or the user account permissions are not sufficient. In network programming, it's thrown when the net connection goes down while fetching a resource. – Jimi Apr 16 '18 at 03:43
  • Thanks for advise. I made the hard code test for both opener app and file: `try { Process.Start(@"D:\Program Files (x86)\Google\Picasa3\PicasaPhotoViewer.exe", @"D:\temp\demo.jpg"); } catch (Exception ex) { Debug.Write(ex.ToString()); }` Now the jpg opens and then (in debug) the application goes to "break mode" an attempt to continue stops the session. The catch block doesn't catch anything. Running the .exe directly will popup the message box " has stopped working". – user3104076 Jun 17 '18 at 07:14

0 Answers0