Opening image via default viewer in .NET Core - .net-core

Built out a Console app to try to open an image in Windows using .NET Core. Kept getting an error.
Process.Start(new ProcessStartInfo(tempFile));
Results in:
Win32Exception: The specified executable is not a valid application
for this OS platform.
What do I need to do to make it open in Windows' default viewer, in my case, the Windows Photo Viewer? For now, I've resorted to display the full image path to copy-paste.
It works if I use .NET 4.6.2, but not .NetCoreApp 1.1. I know its something to do with making it cross-platform friendly(?) but what...
Thanks!

The difference that prevents this from working is that ProcessStartInfo.UseShellExecute defaults to false on .NET Core, and cannot be controlled on Windows. Due to that, the program is trying to launch the image file as an executable, which is not possible. Instead, you can essentially use Process.Start to emulate a shell command in order to open the file with the system's default viewer.
Process.Start("cmd", $"/c {pathToFile}");
Similarly, xdg-open can be used on Linux (generally speaking), and open can be used on OSX.

Related

Use the same environment variable to point to User's Home directory on both Mac and Windows in .net core

I have a .netcore application which reads the log path from appSettings.json.
I want to provide the default path to be something like %HOME%/MyApp/Logs/Log.json.
My code reads and expands the environment variable using Environment.ExpandEnvironmentVariables.
Now the problem is this works on Mac but on windows %HOME% is not expanded. Rather %userprofile% works on Windows.
My question is- can you suggest me some environemt variable that will work on both the platforms? As I said it reads from json, so there is not much option for me to check the platform it's running on.

Qt application running with `-platform offscreen` argument cannot establish websocket connection

I have a GUI application which contains a websocket server QWebSocketServer. I also have a python script which sends messages and the application processes them. Everything works well. During testing I wanted to run the application in headless mode using -platform offscreen command line argument added to the app executable name (I changed nothing else). But the problem is that when the application runs off-screen, the client script cannot establish connection with the web socket server. I tested this on localhost only. I do not understand how this two things, visibility of GUI and websockets, can interfere. Any ideas what could go wrong?
Note: I am using Qt 5.11.1 64-bit with VS 2017 on Windows 10 Pro.
A platform plugin is a bit more than merely "GUI". The -platform option selects a family of platform-specific plugins. Perhaps some plugins that make networking work are absent on that platform spec. That's very likely, since the offscreen platform is only a proof-of-concept: it's to show how you'd write a platform plugin. It's example code, and it does the bare minimum needed. It's nothing that you should be using for production without fully understanding what's there and how it works - it wasn't not meant for it, at least not the last time I looked at it. It shouldn't be hard to make it work, but you'd need to clone the source and start hacking on it.

Desktop app converter fails to run, with: "The data area passed to a system call is too small"

I have installed Desktop App Converter from the Windows store.
When I try to run the app (literally just launch it), I get the message:
[Window Title]
C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.0.2.0_x64__8wekyb3d8bbwe\DACTileLauncher.exe
[Content]
C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.0.2.0_x64__8wekyb3d8bbwe\DACTileLauncher.exe
The data area passed to a system call is too small.
I have tried running the Troubleshooter for Windows Apps, it tells me that "Windows Store cache and licenses may be corrupt" and tries to fix them, but running the troubleshooter a second time gives the same issue.
Each time I try to run the Desktop App Converter, I get 2 errors in Event Viewer:
%1: Cannot create the Desktop AppX container for package %2 because an error was encountered configuring the runtime.
%4: Cannot create the process for package %1 because an error was encountered while configuring runtime. %5
... both from AppModel-runtime
Any ideas how I can troubleshoot from here?
If you have problems with the Microsoft DAC you try this new converter, it is much easier to use, it has a GUI (no command line), built-in support for digital signing and allows you to customize the list of files that get inside your AppX.
Also, you can generate AppX packages for applications which do not (cannot) install silently.
It runs on Windows 7 too, not just Windows 10 (recommended).

flex embedded in html on ubuntu using cherrypy

I'm trying to open an SWF file i created using mxmlc but when i open it in the browser it just shows a white page, and if i embed it into html it shows the grey background ... and when i try to open the html file from localhost (using cherrypy) it just says
Error #2046
and the server shows nothing wrong .. the message appears only in the client
I'm using ubuntu 10.10 and running mxmlc from the terminal.
note: it used to work a couple of minuets ago, i don't know what happened ... i tried to undo changes and no difference.
You have a Runtime Shared Library related error:
This error indicates that the loaded
RSL was not signed properly. In the
case of framework RSLs, the
framework's SWZ file that the
application attempted to load at run
time was not a properly signed SWZ
file. You must ensure that you deploy
an Adobe-signed RSL.
You should update the shared libraries on your server, so the client to download the proper versions to run the flash application.

Adobe AIR NativeProcess - UAC problems when trying to run update installers

I'm trying to use Adobe AIR 2's NativeProcess API to emulate the ApplicationUpdater but I'm encountering problems when I try to run the downloaded AppUpdater.exe file on computers with UAC (User Account Control) enabled.
When run without UAC enabled, the AppUpdater opens as usual and displays the standard Adobe replace dialog box. With UAC enabled, nothing happens at all.
Having run a few traces, it seems the problem arises when I call NativeProcess.start() - the code seems to stop running at this point, and does not run the following lines which exit the application in preparation for the AppUpdater to run.
I have added listeners for all of the possible events and error events that can be thrown, and added logging in each of them, but none of these are producing any output.
This issue only seems to affect installation executables (ones which windows warns will change settings on your computer). Calling java.exe -jar .... on the same computers in the same application works correctly.
I'm at a loss, so any help would be amazing!
After speaking to Adobe directly, I discovered that NativeProcess uses a windows API which is unable to elevate privileges which is why the installers wouldn't work. The workaround was to use File.openWithDefaultApplication which uses a different API that can elevate privileges, but this only works in a native-packaged AIR app (which was just fine for our app since it was already packaged in a native installer :))
adobe answer was http://kb2.adobe.com/cps/404/kb404888.html
but for real steps you should determine the application user privileges and determine UAC enabled, if yes - then warn end-user about it.
I'm expecting that you could do nothing with windows-thing from Adobe Air.

Resources