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

.NET 7.0 preview DragEnter bug after update to latest versions. #7518

Closed
c-ohle opened this issue Jul 29, 2022 · 23 comments · Fixed by #7589
Closed

.NET 7.0 preview DragEnter bug after update to latest versions. #7518

c-ohle opened this issue Jul 29, 2022 · 23 comments · Fixed by #7589
Labels
💥 regression-preview Regression from a preview release

Comments

@c-ohle
Copy link

c-ohle commented Jul 29, 2022

Description

When trying to drag and drop files from folders or other sources into a Windows.Forms.Controls:

NotImplementedException in IDropTargetVtbl.cs
VS2022 preview, .NET 7.0 preview, SDK, all latest versions.

It works compiled for .NET 6.0, it worked for all .NET 7.0 previews before.
Example project is available at GitHub

image

Reproduction Steps

Should be easy to reproduce:
VS2022 - New Project - Windows Forms App - .NET 7.0 preview
Form1 - AllowDrop = true; - override OnDragEnter
on file drop -> exception

Expected behavior

Should work or message/exception if there is a security problem or what ever.

Actual behavior

NotImplementedException

Regression?

No response

Known Workarounds

no

Configuration

Processor: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (2112 MHz) × 8
System: Microsoft Windows 10.0.22622 X64 Runtime: .NET 7.0.0-preview.6.22324.4 X64
BigRational: 1.0.0.5 Runtime: v4.0.30319 .NETCoreApp,Version=v7.0

For Test project on: GitHub sample

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged The team needs to look at this issue in the next triage label Jul 29, 2022
@huoyaoyuan
Copy link
Member

WinForms related issue belongs to https://github.com/dotnet/winforms repo.

Can you provide detailed exception stack trace of the exception, for where it's thrown, WinForm-specific code or the runtime COM interop?

@c-ohle
Copy link
Author

c-ohle commented Jul 30, 2022

@huoyaoyuan problem is that it's not possible to debug in ComInterfaceDispatch... The debugger hangs.
The exception message is: Exception thrown: 'System.NotImplementedException' in System.Windows.Forms.Primitives.dll

@c-ohle
Copy link
Author

c-ohle commented Jul 30, 2022

Here is some more, activated unmanaged debug, exception thrown at last line but can't see GUIDS flags.

 protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags)
    {
        Debug.Assert(flags == CreateObjectFlags.UniqueInstance || flags == CreateObjectFlags.None || flags == CreateObjectFlags.Unwrap);

        Guid pictureIID = IID.IPicture;
        int hr = Marshal.QueryInterface(externalComObject, ref pictureIID, out IntPtr pictureComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new PictureWrapper(pictureComObject);
        }

        Guid errorInfoIID = IID.IErrorInfo;
        hr = Marshal.QueryInterface(externalComObject, ref errorInfoIID, out IntPtr errorInfoComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new ErrorInfoWrapper(errorInfoComObject);
        }

        Guid enumFormatEtcIID = IID.IEnumFORMATETC;
        hr = Marshal.QueryInterface(externalComObject, ref enumFormatEtcIID, out IntPtr enumFormatEtcComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new EnumFORMATETCWrapper(enumFormatEtcComObject);
        }

        Guid fileOpenDialogIID = IID.IFileOpenDialog;
        hr = Marshal.QueryInterface(externalComObject, ref fileOpenDialogIID, out IntPtr fileOpenDialogComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new FileOpenDialogWrapper(fileOpenDialogComObject);
        }

        Guid fileSaveDialogIID = IID.IFileSaveDialog;
        hr = Marshal.QueryInterface(externalComObject, ref fileSaveDialogIID, out IntPtr fileSaveDialogComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new FileSaveDialogWrapper(fileSaveDialogComObject);
        }

        Guid lockBytesIID = IID.ILockBytes;
        hr = Marshal.QueryInterface(externalComObject, ref lockBytesIID, out IntPtr lockBytesComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new LockBytesWrapper(lockBytesComObject);
        }

        Guid shellItemIID = IID.IShellItem;
        hr = Marshal.QueryInterface(externalComObject, ref shellItemIID, out IntPtr shellItemComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new ShellItemWrapper(shellItemComObject);
        }

        Guid shellItemArrayIID = IID.IShellItemArray;
        hr = Marshal.QueryInterface(externalComObject, ref shellItemArrayIID, out IntPtr shellItemArrayComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new ShellItemArrayWrapper(shellItemArrayComObject);
        }

        Guid autoCompleteIID = IID.IAutoComplete2;
        hr = Marshal.QueryInterface(externalComObject, ref autoCompleteIID, out IntPtr autoCompleteComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new AutoCompleteWrapper(autoCompleteComObject);
        }

        Guid enumVariantIID = IID.IEnumVariant;
        hr = Marshal.QueryInterface(externalComObject, ref enumVariantIID, out IntPtr enumVariantComObject);
        if (hr == S_OK)
        {
            Marshal.Release(externalComObject);
            return new EnumVariantWrapper(enumVariantComObject);
        }

        throw new NotImplementedException();

@c-ohle
Copy link
Author

c-ohle commented Jul 30, 2022

It's in WinFormsComWrappers.cs, for the case: drag a single file from Desktop to WinForm or in my case a UserControl class.

@danmoseley danmoseley transferred this issue from dotnet/runtime Jul 30, 2022
@dreddy-work dreddy-work added the 💥 regression-preview Regression from a preview release label Jul 30, 2022
@dreddy-work
Copy link
Member

@kant2002, can you take a quick look to see if your latest changes in anyway causing this?

kant2002 added a commit to kant2002/winforms that referenced this issue Jul 31, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Fixes dotnet#7518
@ghost ghost added the 🚧 work in progress Work that is current in progress label Jul 31, 2022
@kant2002
Copy link
Contributor

I think issue was introduced in #6976

@c-ohle
Copy link
Author

c-ohle commented Jul 31, 2022

@kant2002 Yes, this seems to be the same problem. But there is something more.

Since an earlier NET7 version (3 or so) something is wrong with COM refcounts.
For example in my test app: Previously it was possible to drag and drop 3D objects from the 3D view of one app instance to the 3D view of another app instance.
Now the source app instance hangs after a some deep internal COM exceptions.
Compiled with Target NET 6.0 it works.

So it's easy to reproduce with the app:
https://github.com/c-ohle/RationalNumerics

@c-ohle
Copy link
Author

c-ohle commented Jul 31, 2022

@kant2002 Not really important because the exception is handled but maybe as hint:
This exception is also new since this version. (3 or so) (the exception is in AxIWebBrowser - wrong debug display)

image

@c-ohle
Copy link
Author

c-ohle commented Jul 31, 2022

@kant2002 and one more hint to reproduce:
Drag and drop still works within views of an app instance.
But app exit -1, which has always been a sure sign of a forgotten COM release call.

The program '[14228] Test.exe' has exited with code 4294967295 (0xffffffff).

@merriemcgaw merriemcgaw removed the untriaged The team needs to look at this issue in the next triage label Aug 3, 2022
@merriemcgaw
Copy link
Member

@c-ohle would it be possible for you to provide trimmed down sample code so that we can test the fix from @kant2002 (and hopefully even incorporate it into our test bed somehow)?

@merriemcgaw merriemcgaw added this to the 7.0 RC1 milestone Aug 3, 2022
@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@merriemcgaw hi, the fastest way is really with Test.exe from the Project
It's all up to date, last check in yesterday, based on NET7 dev master-branch
After download change Target framework from NET 6.0 to NET 7.0.
In debug go to TabPage "Polyhedron" and wait for the short animation to finish.
You can move the 3D-objects with mouse. Hold the Control-Key to drag-drop 3D-objects.
This works in the current viewport and also when dragging objects onto the desktop.

  • But dragging the objects from the desktop back into the view fails and the exception occurs.
  • There is also a WB based toolbox (right click). Dragging objects from there fails - same exception.
  • Run a second instance to check drag-drop between views, normally it works.
  • App-exit-code should be 0 (zero). Currently after any drag action (also only within a view) it's -1.

@Olina-Zhang
Copy link
Member

@c-ohle I tested your Test.exe from the Project, can drag-drop 3D objects from "Polyhedron" TabPage to desktop, but it doesn't allow dragging the objects from the desktop back into the view, is there something wrong with my operation?
drag-drop

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang Yes, but that's exactly the problem - the bug in the latest .NET 7.0 preview.
But thanks for testing, now it's certain it's not just my machine.

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang
VS2022 MainMenu\Debug\Windows\Exception Settings
Common Language Runtime Exceptions - select all
Then you get it: 'System.NotImplementedException' in System.Windows.Forms.Primitives.dll

@Olina-Zhang
Copy link
Member

Olina-Zhang commented Aug 3, 2022

@c-ohle we also created a simple repro project about drag-dropping image on pictureBox in Winforms from file explorer, the DragEnter event cannot be triggered in the latest .Net 7.0, can't repro in .Net 6.0. So it is the same issue in here.
WinFormsApp14.zip
drag-drop1

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang good work, now it should be easy for them to reproduce and to add the missing COM interface request.
But please note: There are actually two issues as I mentioned above:

Since an earlier NET7 version (3 or so) something is wrong with COM refcounts.

The other issue is some versions older and deeper in the system and can not reproduce with a "drop target only app".

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang when I switch back to .Net 6.0. it works. Maybe you forgot a rebuild or something?

@Olina-Zhang
Copy link
Member

st .Net 7.0, can't repro in .Net 6.0

yes, this issue cannot repro in Net 6.0, you can see my previous comment. When switch app to .Net 6.0, that DragEnter event can be triggered, I set a breakpoint in that app.

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang with my app too? This could also be a SDK version(s) conflict - it would not be the first time.
To make sure - you can compile and test the same project with Target NET 6.0 in a offical VS2022 (not preview).

@c-ohle
Copy link
Author

c-ohle commented Aug 3, 2022

@Olina-Zhang sorry, yes you said, I misunderstood earlier and focussed on this.

kant2002 added a commit to kant2002/winforms that referenced this issue Aug 13, 2022
Fixes dotnet#7518

Eventually I should improve dotnet#7519 but until then, this is safer approach IMO.

cc @Olina-Zhang  @dreddy-work @RussKie
dreddy-work pushed a commit that referenced this issue Aug 15, 2022
Fixes #7518

Eventually I should improve #7519 but until then, this is safer approach IMO.
@ghost ghost removed this from the 7.0 RC1 milestone Aug 15, 2022
@Amy-Li03
Copy link
Contributor

Verified on .NET 7.0 test pass build: .NET 7.0.100-rc.1.22425.12, issue was fixed, now the DragEnter event can be triggered.
Fixed

@Nora-Zhou01
Copy link
Member

Verified on .NET 8.0 latest build from main branch: NET 8.0.100-alpha.1.22451.15, issue was fixed, test result is same as above screenshot.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 2, 2022
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💥 regression-preview Regression from a preview release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants