"Swing-Shell" java.lang.InternalError: Could not initialize COM: HRESULT=0x80010106 - windows-store

I have a Java 9 app that I'm trying to package for the Windows Store. The strange thing is that it works as expected when I run the exe-launcher directly, but I get the following strange error when I run the launcher via the APPX package:
Exception in thread "Swing-Shell" java.lang.InternalError: Could not
initialize COM: HRESULT=0x80010106
at java.desktop/sun.awt.shell.Win32ShellFolderManager2.initializeCom(Native Method)
at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker$1.run(Unknown Source at java.base/java.lang.Thread.run(Unknown Source)
HRESULT=0x80010106 means RPC_E_CHANGED_MODE which I guess means that COM is somehow already initialized in MTA mode. But why is this only an issue in the Windows Bridge sandbox? Does the Windows Bridge somehow pre-initialize COM somehow for some reason?
I'm not sure if this is a Java 9 issue, or a Desktop Bridge issue, or both. Does anybody have any ideas on how to identify the cause of the issue or workaround?
I have made a minimal Sample Project to reproduce the issue
The application works when executed directly, but not when executed via the APPX launcher. Why?

Analysis
The JDK parts, that rely on COM being initialized (D3DPipeline, Sound and windows shellfolder access) all follow the same pattern:
the run the code in a separate thread
for this thread CoInitialize is called
at the end of the user level code CoUnitialize is called
This is in line with the documentation the MSDN holds for COM and the analysis is correct, the error indicates, that the COM subsystem is already initialized to be MTA threaded.
So I modified the java launcher (jvm.dll) and inserted
debugging statements into some of the native methods in os_windows.cpp.
I focused on the threading methods. What I found was this:
create_main_thread, create_os_thread, pd_start_thread all
run with COM not yet initialized
the native thread initializer (thread_native_entry) is already
running with COM initialized
I looked more into in _beginthreadex and indeed I finally found a lead
on stackoverflow. That pointed me to the sourcecode of threadex.c,
which is part of the Visual Studio 2013 Express Installation.
There you find, that _beginthreadex does not directly start the
supplied thread function, but runs a library initializer
(_threadstartex) first. Part of this initializer reads:
_ptd->_initapartment = __crtIsPackagedApp();
if (_ptd->_initapartment)
{
_ptd->_initapartment = _initMTAoncurrentthread();
}
_callthreadstartex();
_crtIsPackagedApp detects via a kernel function if the application is
run as a "PackagedApp" (i.e. AppX package) and if so, then the
RoInitialize function is called, which from my understanding acts like the big
brother of CoInitialize.
Long story short: If your application is build with Visual Studio 2013
and run as a packaged application, you get a broken environment.
It was confirmed, that the working versions of the Oracle JDK were build with VS2010 SP1 and the broken version was build with VS2013SP4.
Workaround
With the above information google finally found a reference, that supports the analysis:
https://blogs.msdn.microsoft.com/vcblog/2016/07/07/using-visual-c-runtime-in-centennial-project/
Quote from that article:
Note that the existing VC++ 12.0 libraries created during the
Windows 8 timeframe have runtime checks to determine whether the
app is running under the app container or not. When running
desktop apps as a packaged app, these checks might limit the
functionality of the desktop app or cause it to behave like a UWA
(Universal Windows Application) (limited file system access or
create thread initializing MTA etc.). We have fixed this behavior
in the VC++ libraries contained in these framework packages and
thus removing the modern app limitations from your desktop
applications.
So I see to options to fix applications, that shall be distributed as AppX packages:
either force the users to have the updates VC++ 12.0 binaries installed (by introducing the dependency cited in the blog post) or
replace the msvcr120.dll that is bundled with Java 9 (and I assume also Java 10) with the fixed version from the update packages
I would go with the second version and I tested this. Starting with a clean up-to-date Windows 10 System, I installed JDK 9.0.4, I cloned the supplied testcase, modified it use the locally installed JRE (not the JDK!) and build the appx package. Running this, I reproduced the problem. I then replaced the msvcr120.dll's in the JRE folder of my systems installation with the one contained in the APPX container from:
https://www.microsoft.com/en-us/download/details.aspx?id=53176
Hint: *.appx are just ZIP files with additional signatures, so you can
just rename them and extract the contents.
I rebuild the testcase and it is working as it should (no COM
initialization errors anymore).

Related

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).

Matlab generates x86 dll but it needs to be x64

I have some trouble with my asp.net application which uses matlab functions inside.
I generated matlab function on matlab R2016a and then I generated Dll's via matlab compiler / dotnetbuilder.
At localhost, I build a MVC Web application with VS2013 which takes an integer input and on backend it generates random numbers counts input than matlab function gets the average of these random numbers.
However, it works fine on localhost but it fails on server with Matlab Compiler Runtime 9.0.1 installed. Exception is:
"Unable to load DLL 'mclmcrrt9_0_1.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
So I lookup with the dependency walker and I see this;
focused line is belong to the dll that generated via matlab Library compiler of R2016a
It says that matlabs generated dll is in cpu type of x86 even whole application is in x64.
Questions:
1) How can I fix this issue
2) Why this application runs with no exceptions on my own PC
any answers appreciated, if you need any other information just tell me.
I did the same and have the same problem, Problem didn't solve until I restart the server because of new Environment Variable which defined in windows system after installing Matlab RunTime.
so first restart server.
and be sure that you complied dll with matlab 64bits if use 64bits server.

How to implement a "quit to upgrade and restart" installer?

Many applications have this functionality now, but a good example is the Spotify client.
The app discovers there is a new version available, downloads it in the background then prompts the user to restart to get the new version. When the user quits the new version is installed (or the installed version is patched) then the application is restarted, all without further user interaction. In fact, the user really doesn't even have to do anything the app would automatically update on every exit if the user was never notified.
We have a cross-platform Qt 5.3 application and our lean startup business model requires us to push application updates very often so I'd really like to find a method that works cross platform with as little platform specific code as possible.
There are multiple parts to this question.
Noticing the update, and downloading the installer. (Obvious, and not a problem)
Running the installer application. Not an issue except how does one gain privilege? Spotify never asks for privilage to install again after the first install.
Avoiding "This application has been downloaded from the Internet" approval dialogue on every update.
Restarting the application after upgrading, but only when the user responded to the quit and upgrade prompt.
Specifically are there any tools, installers or code examples that do this?
You can follow how Google Chrome and Opera (latest one, not version <= 12) do it, rougly as below:
When installing the application, create a scheduled task that runs an updater as administrator (or a user with permission to write files to your application directory) periodically. For example in Windows, you can find GoogleUpdateTaskMachineCore and GoogleUpdateTaskMachineUA entries in Task Scheduler.
Your application structure looks something like the following (Google Chrome has similar structure in C:\Program Files (x86)\Google\Chrome\Application):
C:\Program Files\AwesomeApp\launcher.exe
C:\Program Files\AwesomeApp\1.0\AwesomeApp.exe ; version 1.0 of application
C:\Program Files\AwesomeApp\1.2\AwesomeApp.exe ; version 1.2 of application
The application shortcut created by installer will run launcher.exe. This launcher.exe will run the latest version of AwesomeApp.exe available in the directory. For example in the above structure, launcher.exe will run AwesomeApp\1.2\AwesomeApp.exe.
When the updater finds an update, it will download it and add the new version to the directory in the background. After that it will tell the running application (if it is running) to notify the user that an update is ready and can be used by restarting the application. And of course your older application needs to close itself and restart by running launcher.exe too. This updater may delete old application versions and keep only the latest two versions.

Flex release build issue (AIR application)

I have an issue on exported build release from Flash Builder 4.6. The case is when I run it on the IDE(Flash Builder 4.6) it works fine, no issues encountered, it never crashed but when I exported it for a release build and run, it crashes to a certain module/view. The view/module where the AIR app crashes has multiple remote object calls (minimum of 5). I have noticed that when requesting multiple remote object calls(like 5 remote calls at a time) it crashes. Is the remote object causes the crash? Please help me out on this guys, any idea will be much appreciated.
Thanks
Glen
I bet it's a security issue that you worked around when invoking the application from the ide. By default, Flash Builders working directories are marked as "secure", so you don't get any security issues. But when working on the live system, you might need to have a corssdomain policy.
Also: i suggest to use the Thunderbolt logger with the logging framework. This allows you to get log informations straight into your browser's console.

Resources