Skip to content

[dotnet-sdk-7.0.100-preview.3.22118.7] Greenshot and NugetPackageExplorerget apps get exception When do saving the file operation #6748

@Junjun-zhao

Description

@Junjun-zhao

Description

When running Greenshot with .NET 7.0 Preview 3 runtime, it will get exception when do saving the file operation.

Reproduction Steps

Repro steps for the affected app:

This is .Net 5.0 app, but we are running it on 7.0, machine only have 7.0 installed, and DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2, so it runs on 7.0.

1.Copy App from App Path and launch Greenshot.exe.
2.Click “OK” button.
3.Press Print Screen key.
4.Take a screenshot by dragging the cursor down a little and releasing the left button click.
5.Choose Save as (displaying dialog) menu item.

Minimal Repro steps:
dotnet-sdk-7.0.100-preview.322118.7 sdk should be installed on the machine.
Sample code attached.
WinFormsApp1 (2).zip

  1. Create .net 5.0 Winform app
  2. Add SaveFileDialog and Button Component to form
  3. In Button click event, write this :
 private void button1_Click(object sender, EventArgs e)
        {
             var dialog = new System.Windows.Forms.SaveFileDialog()
            {
               InitialDirectory = @"C:\Users\v-zhiyang\Documents"
            };
            try
            {
                var result = dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
  1. Publish the app and change the runtime.json file to use 7.0.0-preview.3.22116.6 for Microsoft.WindowsDesktop.App under publish folder.
{
  "runtimeOptions": {
    "tfm": "net5.0",
    "framework": {
      "name": "Microsoft.WindowsDesktop.App",
      "version": "7.0.0-preview.3.22116.6"
    }
  }
}
  1. Start the project with F5.
  2. Click "button1" Button.

Expected behavior

It shows save window.

Actual behavior

Actual Result for the Affected App:
It shows error and crash.

Application: Greenshot.exe
Microsoft.WindowsDesktop.App version: 7.0.0-preview.3.22116.6
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidCastException: 
System.NotImplementedException: ComWrappers for type System.__ComObject not implemented.
   at Interop.WinFormsComWrappers.ComputeVtables(Object obj, CreateComInterfaceFlags flags, Int32& count)
   at System.Runtime.InteropServices.ComWrappers.<TryGetOrCreateComInterfaceForObjectInternal>g____PInvoke__|7_0(ObjectHandleOnStack comWrappersImpl, Int64 wrapperId, ObjectHandleOnStack instance, CreateComInterfaceFlags flags, IntPtr* retValue)
   at System.Runtime.InteropServices.ComWrappers.TryGetOrCreateComInterfaceForObjectInternal(ObjectHandleOnStack comWrappersImpl, Int64 wrapperId, ObjectHandleOnStack instance, CreateComInterfaceFlags flags, IntPtr& retValue)
   at System.Runtime.InteropServices.ComWrappers.TryGetOrCreateComInterfaceForObjectInternal(ComWrappers impl, Object instance, CreateComInterfaceFlags flags, IntPtr& retValue)
   at System.Runtime.InteropServices.ComWrappers.GetOrCreateComInterfaceForObject(Object instance, CreateComInterfaceFlags flags)
   at Interop.WinFormsComWrappers.GetOrCreateComInterfaceForObject(Object obj)
   at Interop.WinFormsComWrappers.GetComPointer[T](T obj, Guid iid)
   at Interop.WinFormsComWrappers.FileDialogWrapper.Interop.Shell32.IFileDialog.SetDefaultFolder(IShellItem psi)
   at System.Windows.Forms.FileDialog.OnBeforeVistaDialog(IFileDialog dialog)
   at System.Windows.Forms.FileDialog.TryRunDialogVista(IntPtr hWndOwner, Boolean& returnValue)
   at System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
   at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
   at Greenshot.Addons.Controls.SaveImageFileDialog.ShowDialog() in C:\.NETCoreUpgradeApps\AppSources\greenshot\src\Greenshot.Addons\Controls\SaveImageFileDialog.cs:line 212
   at Greenshot.Addons.Core.ImageOutput.SaveWithDialog(ISurface surface, ICaptureDetails captureDetails) in C:\.NETCoreUpgradeApps\AppSources\greenshot\src\Greenshot.Addons\Core\ImageOutput.cs:line 122
   at Greenshot.Destinations.FileWithDialogDestination.ExportCapture(Boolean manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) in C:\.NETCoreUpgradeApps\AppSources\greenshot\src\Greenshot\Destinations\FileWithDialogDestination.cs:line 59
   at Greenshot.Addons.Core.AbstractDestination.ExportCaptureAsync(Boolean manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) in C:\.NETCoreUpgradeApps\AppSources\greenshot\src\Greenshot.Addons\Core\AbstractDestination.cs:line 159
   at Greenshot.Addons.Core.AbstractDestination.<>c__DisplayClass42_0.<<ShowPickerMenu>b__6>d.MoveNext() in C:\.NETCoreUpgradeApps\AppSources\greenshot\src\Greenshot.Addons\Core\AbstractDestination.cs:line 367
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Actual Result for the Minimal Demo:

Get below exception:
System.NotImplementedException: ComWrappers for type System.__ComObject not implemented.

Regression?

Yes

Verify Scenarios:

1). Windows10 RS5 x64+dotnet-sdk-7.0.100-preview.3.22118.7: Fail
2). Windows10 RS5 x64+dotnet-sdk-7.0.100-preview.3.22122.1: Fail
3). Windows10 RS5 x64+dotnet-sdk-7.0.100-preview.2.22114.1: Pass
4). Windows10 RS5 x64+dotnet-sdk-5.0.405-win-x64 (Default SDK): Pass

Known Workarounds

No response

Configuration

Application Name: Greenshot & NugetPackageExplorer
OS: Windows 10 RS5
CPU: X64
.NET Build Number: dotnet-sdk-7.0.100-preview.3.22118.7

Github link for source code:
https://github.com/greenshot/greenshot

App and App Source Checking at : https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1487350

Other information

Findings:

When we create SaveFileDialog object, InitialDirectory will report an exception:
InitialDirectory = @"C:\Users\v-zhiyang\Documents"

@dotnet-actwx-bot @dotnet/compat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions