Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displayed Windows Forms Controls Differ in Single File Deployment #42593

Closed
ab-tools opened this issue Sep 22, 2020 · 13 comments
Closed

Displayed Windows Forms Controls Differ in Single File Deployment #42593

ab-tools opened this issue Sep 22, 2020 · 13 comments

Comments

@ab-tools
Copy link

Description

Steps to reproduce:

  1. Load this simple example project: WindowsFormsApp6.zip
  2. Publish it with profile "Self-Contained" and run it - it will look like this on Windows 10 64 Bit:
    image
  3. Publish it with profile "Self-Contained-Single-File" and run it - it will look like this on Windows 10 64 Bit:
    image

Expected Behavior:

No matter if published as single file or not the Windows Forms controls should be displayed the same when executed in the same Windows environment.

Configuration

  • .NET Version 5.0 RC1
  • Windows 10.0.18363 64 Bit
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Single-File untriaged New issue has not been triaged by the area owner labels Sep 22, 2020
@ghost
Copy link

ghost commented Sep 22, 2020

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Sep 22, 2020
@agocke agocke added this to the 6.0.0 milestone Sep 22, 2020
@vitek-karas
Copy link
Member

Thanks for reporting!

Workaround is to add a manifest to your app and add the "enable themes for common controls" section:

  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

Then it works in both cases the same.
I don't really know why it fails to work without the manifest @AaronRobinsonMSFT any idea - maybe something to do with app contexts?

@jkotas
Copy link
Member

jkotas commented Sep 30, 2020

Related to dotnet/sdk#12904 ?

@vitek-karas
Copy link
Member

Thanks @jkotas - definitely related, but there's something else going on here:

  • publishing the app as self-contained (non-single-file) -> works without the custom manifest
  • publishing the app as self-contained single-file -> doesn't work without the custom manifest
  • publishing the app as framework dependent (non-single-file) -> works
  • publishing the app as framework dependent single-file -> works

So the only difference I can think of is that the failing case is using singlefilehost, while all the other cases are using apphost. But I don't see a difference in the two which would cause this...

@AaronRobinsonMSFT
Copy link
Member

@vitek-karas Agreed on this issue being related to Windows 10 support. If memory serves the Windows 10 styling is included when support is indicated in the manifest. Do we know the manifest situation in the apphost vs singlefilehost?

@vitek-karas
Copy link
Member

I looked at the manifests of apphost and singlefilehost as produced by the repro - and they are identical (baring any mistakes I might have made). That's what's really weird - as far as I can tell the two binaries look the same.

@AaronRobinsonMSFT
Copy link
Member

@jkotas Boo. That is unfortunate. We should also check out WPF I guess.

@vitek-karas
Copy link
Member

WPF at least by default should be OK as it does all of its rendering, unlike WinForms which relies on the OS. But there definitely could be some other problems.

This is basically "WinForms is currently not fully compatible with single-file" - unfortunately. Not sure what the fix is though - I can't find a way to create activation context without a file on disk in Win32 APIs. We would have to make this a resource of the singlefilehost - which is definitely doable.

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Oct 2, 2020

We would have to make this a resource of the singlefilehost - which is definitely doable.

Yep. That is a requirement for the activation context - at least my understanding. I used an Activation Context in CoreRun.

ActivationContext(Logger &logger, _In_z_ const WCHAR *assemblyPath)
: _logger{ logger }
, _actCxt{ INVALID_HANDLE_VALUE }
, _actCookie{}
{
ACTCTX cxt{};
cxt.cbSize = sizeof(cxt);
cxt.dwFlags = (ACTCTX_FLAG_APPLICATION_NAME_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID);
cxt.lpSource = assemblyPath;
cxt.lpResourceName = MAKEINTRESOURCEW(1); // The CreateProcess manifest which contains the context details
_actCxt = ::CreateActCtxW(&cxt);
if (_actCxt == INVALID_HANDLE_VALUE)
{
DWORD err = ::GetLastError();
if (err == ERROR_RESOURCE_TYPE_NOT_FOUND)
{
_logger << W("Assembly does not contain a manifest for activation") << Logger::endl;
}
else
{
_logger << W("Activation Context creation failed. Error Code: ") << Logger::hresult << err << Logger::endl;
}
}
else
{
BOOL res = ::ActivateActCtx(_actCxt, &_actCookie);
if (res == FALSE)
_logger << W("Failed to activate Activation Context. Error Code: ") << Logger::hresult << ::GetLastError() << Logger::endl;
}
}

@ab-tools
Copy link
Author

ab-tools commented Jan 24, 2021

Just retested this again with Visual Studio 16.9.0 Preview 3 and .NET SDK 5.0.200.preview.20614.14 and looks like things got worse:
Now the Windows Forms application crashes upon application start when published using single file deployment as soon as System.Windows.Forms.Application.EnableVisualStyles() gets called:

System.IO.FileNotFoundException: The system cannot find the file specified. (0x80070002)
   at System.Reflection.RuntimeModule.GetFullyQualifiedName()
   at System.Reflection.RuntimeModule.get_Name()
   at System.Windows.Forms.Application.EnableVisualStyles()

This happens with or without the manifest mentioned above.

@vitek-karas
Copy link
Member

The underlying problem is #40103.
Just to prove it - you can try running the app from the Visual Studio Developer Command Prompt - it works for me (and fails without that).

The fix in progress here: #47437

@vitek-karas
Copy link
Member

With #47464 the behavior should be consistent no matter the environment - meaning it should always fail. We think this regression happened because those who tested it happen to run in an environment where it worked.

@agocke agocke closed this as completed Aug 16, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants