question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jkotascommented, Feb 23, 2022

I am sure that it will repro with the latest daily build.

In case you need to download specific build of the SDK, the easiest way is to use dotnet-install script. For example, .\dotnet-install.ps1 -v 7.0.100-preview.3.22118.7. You can then find commit SHA for each .dll by looking at the .dll version resource.

0reactions
Ashley-Licommented, Apr 6, 2022

Verified this issue with .NET SDK 7.0.100-preview.3.22179.4 build, this issue was fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The future of Greenshot for Windows
Greenshot - a free screenshot tool optimized for productivity.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found