[Bug 41727] rundll32.exe reports 'This application could not be started' during WINEPREFIX update with .NET Framework 4.0 installed only (unmanaged processes trigger legacy CLR 2.0 activation policy)

WineHQ Bugzilla wine-bugs at winehq.org
Wed May 6 15:22:01 CDT 2020


https://bugs.winehq.org/show_bug.cgi?id=41727

Anastasius Focht <focht at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
            Summary|rundll32.exe error during   |rundll32.exe reports 'This
                   |wine prefix update when     |application could not be
                   |native .NET is installed    |started' during WINEPREFIX
                   |                            |update with .NET Framework
                   |                            |4.0 installed only
                   |                            |(unmanaged processes
                   |                            |trigger legacy CLR 2.0
                   |                            |activation policy)
         Resolution|---                         |INVALID
                 CC|                            |focht at gmx.net
           Keywords|                            |dotnet

--- Comment #5 from Anastasius Focht <focht at gmx.net> ---
Hello folks,

the issue is by design if you have only .NET Framework 4.x installed in the
WINEPREFIX. Every time a WINEPREFIX update is triggered (due to Wine upgrade),
'regsvr32 mscoree.dll' is run. Two times if you have a 64-bit prefix which is
the default nowadays.

It's quite easy to reproduce even without WINEPREFIX update:

--- snip ---
$ rm -rf ~/.wine

$ winetricks -q dotnet40

$ WINEDEBUG=+msgbox wine "c:\\windows\\system32\\regsvr32.exe"
"c:\\windows\\system32\\mscoree.dll"

0024:trace:msgbox:MSGBOX_OnInit L"Unable to find a version of the runtime to
run this application."
regsvr32: Failed to register DLL 'c:\windows\system32\mscoree.dll'

$ WINEDEBUG=+msgbox wine "c:\\windows\\syswow64\\regsvr32.exe"
"c:\\windows\\syswow64\\mscoree.dll"

0024:trace:msgbox:MSGBOX_OnInit L"Unable to find a version of the runtime to
run this application."
regsvr32: Failed to register DLL 'c:\windows\syswow64\mscoree.dll'
--- snip ---

https://source.winehq.org/git/wine.git/blob/HEAD:/loader/wine.inf.in#l2554

--- snip ---
2554 [RegisterDllsSection]
2555 ;;some dlls have to be registered first
...
2564 11,,mscoree.dll,1
--- snip ---

64-bit part:

--- snip ---
002c:Call KERNEL32.CreateProcessW(0021e930
L"C:\\windows\\system32\\rundll32.exe",00715e80
L"C:\\windows\\system32\\rundll32.exe setupapi,InstallHinfSection
DefaultInstall 128
\\\\?\\Z:\\home\\focht\\projects\\wine\\mainline-install-x86_64\\bin\\..\\share\\wine\\wine.inf",00000000,00000000,100000000,00000000,00000000,00000000,0021e8c0,0021e8a8)
ret=140006464 
...
002c:trace:process:CreateProcessInternalW started process pid 00a4 tid 00a8
...
002c:Ret  KERNEL32.CreateProcessW() retval=00000001 ret=140006464
...
00a8:Call user32.MessageBoxW(00000000,0021a1b8 L"This application could not be
started.\n\nDo you want to view information about this issue?",0021a818
L"rundll32.exe - This application could not be started.",00000014) ret=0277d73b 
--- snip ---

32-bit part:

--- snip ---
...
002c:Call KERNEL32.CreateProcessW(0021e930
L"C:\\windows\\syswow64\\rundll32.exe",00ad8630
L"C:\\windows\\syswow64\\rundll32.exe setupapi,InstallHinfSection Wow64Install
128
\\\\?\\Z:\\home\\focht\\projects\\wine\\mainline-install-x86_64\\bin\\..\\share\\wine\\wine.inf",00000000,00000000,100000000,00000000,00000000,00000000,0021e8c0,0021e8a8)
ret=140006464 
...
002c:trace:process:CreateProcessInternalW started process pid 0110 tid 0114 
...
002c:Ret  KERNEL32.CreateProcessW() retval=00000001 ret=140006464 
...
0114:Call user32.MessageBoxW(00000000,0031b2e0 L"This application could not be
started.\n\nDo you want to view information about this issue?",0031acb0
L"rundll32.exe - This application could not be started.",00000014) ret=0245fb3c 
--- snip ---

The error message is misleading at best. In this case it means that the CLR
bootstrapper can't find the needed CLR version. 'regsvr32' is an unmanaged
process that is not supposed to host a .NET runtime. .NET Framework 4.x
'mscoree' and it's shim dlls fall back to legacy v2 CLR hosting behaviour when
they detect that the hosting process is unmanaged and the (calling) main PE not
even a mixed-mode assembly.

It's kind of in between the lines in these articles:

*
https://web.archive.org/web/20091206135954/http://msdn.microsoft.com/en-us/magazine/ee819091.aspx
("In-Process Side-by-Side")

*
http://web.archive.org/web/20130128072944/http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7-900900e451f9.aspx
("What is useLegacyV2RuntimeActivationPolicy for?")

*
https://stackoverflow.com/questions/1604663/what-does-uselegacyv2runtimeactivationpolicy-do-in-the-net-4-config
("What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config")

There are multiple ways to work around these annoying message boxes when the
WINEPREFIX gets updated:

1) install .NET Framework 2.0 before .NET Framework 4.0 (via 'winetricks)

2) create app.config for Wine builtin 'regsvr32' when you have .NET Framework
4.0 or higher only installed:

--- snip ---
...
00a8:Call KERNEL32.CreateFileW(00bcd800
L"C:\\windows\\system32\\rundll32.exe.config",80000000,00000001,00000000,00000003,00000080,00000000)
ret=02747847
....
00a8:Ret  KERNEL32.CreateFileW() retval=ffffffffffffffff ret=02747847 
...
--- snip ---

* 'C:\\windows\\system32\\rundll32.exe.config'
* 'C:\\windows\\syswow64\\rundll32.exe.config'

Content:

--- snip ---
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0" />
  </startup>
</configuration>
--- snip ---

3) Export specific environment variables or set registry keys:

https://github.com/kosmos-zhang/dotnet.coreclr/blob/master/Documentation/project-docs/clr-configuration-knobs.md 

* OnlyUseLatestCLR (big hammer/red knob)

* COMPlus_NoGuiFromShim (not really solution as there is still internal error,
just causes no UI dialogs to be displayed)

* ErrorDialog ((not really solution as there is internal error, causes no error
dialogs to be displayed)

For the environment variable approach you need to add 'COMPLUS_' prefix to
variables:

--- snip ---
...
00a8:Call KERNEL32.GetEnvironmentVariableW(0021bd70
L"COMPLUS_OnlyUseLatestCLR",00000000,00000000) ret=027469f9
00a8:trace:process:GetEnvironmentVariableW (L"COMPLUS_OnlyUseLatestCLR"
0000000000000000 0)
...
00a8:Ret  KERNEL32.GetEnvironmentVariableW() retval=00000000 ret=027469f9
--- snip ---

This works:

--- snip ---
$ COMPlus_OnlyUseLatestCLR=1 wine "c:\\windows\\syswow64\\regsvr32.exe"
"c:\\windows\\syswow64\\mscoree.dll"

regsvr32: Successfully registered DLL 'c:\windows\syswow64\mscoree.dll'
--- snip ---

But that's not really feasible because you would need to persist this
environment variable permanently in Wine environment to be visible during
prefix update.

The better way is to add 'OnlyUseLatestCLR' registry key with DWORD value '1'

--
00a8:Call advapi32.RegOpenKeyExW(ffffffff80000002,027a7a00
L"Software\\Microsoft\\.NETFramework",00000000,00020019,0021be58) ret=02747db4
...
00a8:Ret  advapi32.RegOpenKeyExW() retval=00000000 ret=02747db4
00a8:Call advapi32.RegQueryValueExW(000000a4,027a8808
L"OnlyUseLatestCLR",00000000,0021bee0,0021bed0,0021bec8) ret=0274bfe4
...
00a8:Ret  ntdll.NtQueryValueKey() retval=c0000034 ret=7b03bd38
00a8:Ret  advapi32.RegQueryValueExW() retval=00000002 ret=0274bfe4
--- snip ---

--- snip ---
$ wine reg add "HKLM\\Software\\Microsoft\\.NETFramework" /v OnlyUseLatestCLR
/t REG_DWORD /d 0001 /f

With that registry key in place the registration succeeds:

--- snip ---
$ wine "c:\\windows\\system32\\regsvr32.exe"
"c:\\windows\\system32\\mscoree.dll"

regsvr32: Successfully registered DLL 'c:\windows\system32\mscoree.dll'

$ wine "c:\\windows\\syswow64\\regsvr32.exe"
"c:\\windows\\syswow64\\mscoree.dll"

regsvr32: Successfully registered DLL 'c:\windows\syswow64\mscoree.dll'
--- snip ---

Summarizing: There is nothing to fix in Wine here, it behaves correctly.

To prevent these annoying message boxes which require user interaction to
unblock the WINEPREFIX update we could change the 'dotnet40' recipe to add
'OnlyUseLatestCLR' setting by default.

$ wine --version
wine-5.7-256-g1976685a0f

Regards

-- 
Do not reply to this email, post in Bugzilla using the
above URL to reply.
You are receiving this mail because:
You are watching all bug changes.


More information about the wine-bugs mailing list