Code Monkey home page Code Monkey logo

Comments (30)

shiena avatar shiena commented on June 15, 2024 5

A bug has been registered on the issue tracker.
Please vote for early fix.
https://issuetracker.unity3d.com/issues/windows-com-throws-the-invalidprogramexception-when-using-ookii-dot-dialogs-library

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 4

I have submitted a bug report to Unity regarding this error.
Currently under review, there was no problem up to Unity2023.2.0a14, and it was found that an error occurred from Unity2023.2.0a15.

from unitystandalonefilebrowser.

Peter226 avatar Peter226 commented on June 15, 2024 2

"In progress" on issue trackerπŸ™

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 2

@anonymous2585 I tried it with Unity2023.2.12f1 and the dialog worked.
This is that Unity project.
https://www.dropbox.com/t/52h90sq5zGbxrvvf

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 2

@achimmihca

diff --git a/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs b/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs
index 2bdb8c218..b1e379220 100644
--- a/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs
+++ b/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs
@@ -4,7 +4,13 @@ using System;
 using System.IO;
 using System.Windows.Forms;
 using System.Runtime.InteropServices;
+#if UNITY_2023_2
+using VistaOpenFileDialog = System.Windows.Forms.OpenFileDialog;
+using VistaFolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog;
+using VistaSaveFileDialog = System.Windows.Forms.SaveFileDialog;
+#else
 using Ookii.Dialogs;
+#endif
 
 namespace SFB {
     // For fullscreen support

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 1

@Thaina
I deleted the Ookii.Dialogs.dll and replaced it with the source, but the same error occurs, so I don't think it is caused by the dotnet standard update.

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 1

@zadinvit You can use OpenFileDialog with System.Windows.Forms.dll. However, the old style dialog is displayed.

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 1

@anonymous2585
Yes, unfortunately in the mono version of FileDialog, the AutoUpgradeEnabled property does not work, so the old style dialog is displayed.
https://github.com/Unity-Technologies/mono/blob/unity-main/mcs/class/System.Windows.Forms/System.Windows.Forms/FileDialog.cs#L387-L392
Therefore, you have two options: use Unity 2023.1 or earlier, or wait until the bug is fixed.

Also, the mono version of System.Windows.Forms.dll exists in the following path.

[Unity installed folder]\Editor\Data\MonoBleedingEdge\lib\mono\gac\System.Windows.Forms\4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 1

Perhaps Unity-Technologies/mono#2003 will fix it.

from unitystandalonefilebrowser.

TautvydasZilys avatar TautvydasZilys commented on June 15, 2024 1

Perhaps Unity-Technologies/mono#2003 will fix it.

Yes, that is exactly what that PR fixes :).

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024 1

Backports also merged into 2023.2 and 2023.3.

from unitystandalonefilebrowser.

qq294716498 avatar qq294716498 commented on June 15, 2024

I'm having the same issue. Any solutions?

from unitystandalonefilebrowser.

realrandombeans avatar realrandombeans commented on June 15, 2024

Have the same error here, urgent issue, needs to be fixed ASAP

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024

When I downloaded Ookii.Dialog.dll from below and replaced it, the following error message was output.
https://www.ookii.org/software/dialogs/

InvalidProgramException: Invalid IL code in (wrapper managed-to-native) Ookii.Dialogs.Interop.IFileDialog:Advise (intptr,Ookii.Dialogs.Interop.IFileDialogEvents,uint&): IL_0025: ldloc     65535


(wrapper cominterop) Ookii.Dialogs.Interop.IFileDialog.Advise(Ookii.Dialogs.Interop.IFileDialogEvents,uint&)
(wrapper cominterop-invoke) Ookii.Dialogs.Interop.IFileDialog.Advise(Ookii.Dialogs.Interop.IFileDialogEvents,uint&)
Ookii.Dialogs.VistaFileDialog.SetDialogProperties (Ookii.Dialogs.Interop.IFileDialog dialog) (at <31af777adad04cb788cee0ae18e55ae1>:0)
Ookii.Dialogs.VistaOpenFileDialog.SetDialogProperties (Ookii.Dialogs.Interop.IFileDialog dialog) (at <31af777adad04cb788cee0ae18e55ae1>:0)
Ookii.Dialogs.VistaFileDialog.RunFileDialog (System.IntPtr hwndOwner) (at <31af777adad04cb788cee0ae18e55ae1>:0)
Ookii.Dialogs.VistaFileDialog.RunDialog (System.IntPtr hwndOwner) (at <31af777adad04cb788cee0ae18e55ae1>:0)
System.Windows.Forms.CommonDialog.ShowDialog (System.Windows.Forms.IWin32Window owner) (at <6d56e0f579f14156bf364f450d98bf76>:0)
(wrapper remoting-invoke-with-check) System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
SFB.StandaloneFileBrowserWindows.OpenFilePanel (System.String title, System.String directory, SFB.ExtensionFilter[] extensions, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs:38)
SFB.StandaloneFileBrowser.OpenFilePanel (System.String title, System.String directory, SFB.ExtensionFilter[] extensions, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowser.cs:51)
SFB.StandaloneFileBrowser.OpenFilePanel (System.String title, System.String directory, System.String extension, System.Boolean multiselect) (at Assets/StandaloneFileBrowser/StandaloneFileBrowser.cs:39)

Currently, Ookii.Dialogs has been deprecated and has been migrated to Ookii.Dialogs-Wpf, so it does not work as is.

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024

Since the dialog can be opened in unity2023.1, it may be a bug in unity2023.2.

from unitystandalonefilebrowser.

Thaina avatar Thaina commented on June 15, 2024

I have suspect that it's about unity upgrade dotnet standard from 2.0 to 2.1, which ooki dialog may not been built for?

from unitystandalonefilebrowser.

zadinvit avatar zadinvit commented on June 15, 2024

Hi, is there any workaround? @shiena Did update to Ookii.Dialogs.WinForms help? Or we just need wait for unity fix?

from unitystandalonefilebrowser.

anonymous2585 avatar anonymous2585 commented on June 15, 2024

@shiena Were you able to use OpenFileDialog with System.Windows.Forms.dll?

Even with only this simple code, I have the following exception (Unity 2023.2.7f1 and 2023.2.12f1):

using System.Windows.Forms;

public class WindowsFileBrowser
{
    public static string BrowseFolderPanel(string initialSelectedPath = "")
    {    
        string filePath = string.Empty;    
        using (OpenFileDialog openFileDialog = new OpenFileDialog())
        {
            openFileDialog.InitialDirectory = initialSelectedPath;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filePath = openFileDialog.FileName;
            }
        }
        return filePath;
    }
}
InvalidProgramException: Invalid IL code in (wrapper managed-to-native) System.Windows.Forms.FileDialogNative/IFileDialog:SetDefaultExtension (intptr,string): IL_000e: ldloc     65535
(wrapper cominterop) System.Windows.Forms.FileDialogNative+IFileDialog.SetDefaultExtension(string)
(wrapper cominterop-invoke) System.Windows.Forms.FileDialogNative+IFileDialog.SetDefaultExtension(string)
System.Windows.Forms.FileDialog.OnBeforeVistaDialog (System.Windows.Forms.FileDialogNative+IFileDialog dialog) (at <187ea5586d6f4ba8a9a85a7c10b078e1>:0)
System.Windows.Forms.FileDialog.RunDialogVista (System.IntPtr hWndOwner) (at <187ea5586d6f4ba8a9a85a7c10b078e1>:0)
System.Windows.Forms.FileDialog.RunDialog (System.IntPtr hWndOwner) (at <187ea5586d6f4ba8a9a85a7c10b078e1>:0)
System.Windows.Forms.CommonDialog.ShowDialog (System.Windows.Forms.IWin32Window owner) (at <187ea5586d6f4ba8a9a85a7c10b078e1>:0)
System.Windows.Forms.CommonDialog.ShowDialog () (at <187ea5586d6f4ba8a9a85a7c10b078e1>:0)
(wrapper remoting-invoke-with-check) System.Windows.Forms.CommonDialog.ShowDialog()
WindowsFileBrowser.BrowseFolderPanel (System.String initialSelectedPath) (at Assets/WindowsFileBrowser.cs:79)

from unitystandalonefilebrowser.

anonymous2585 avatar anonymous2585 commented on June 15, 2024

Thanks a lot!
With your project, I understood why I had the issue.
My System.Windows.Forms.dll file comes from the .NET Framwork (version 4.8.4494.0, 5,64Mo) while yours is from Mono (version 4.6.57.0, 2,74Mo).
With your version of the dll, it works! But the dialog is too ugly for me to give that to our clients 😐

from unitystandalonefilebrowser.

achimmihca avatar achimmihca commented on June 15, 2024

Nice to know that there is a workaround, even if the UI is a bit outdated.

Could you please create a branch (or Pull Request) for the workaround?
This way one could easily use the workaround by changing the version of StandaloneFileBrowser to be used via Unity's manifest.json

Note that the workaround does not need to be merged into the master branch. Just having it available as a branch should suffice. And the branch can be deleted once Unity fixes the root problem.

from unitystandalonefilebrowser.

MadStark avatar MadStark commented on June 15, 2024

Yep, same issue with 2023.2+ πŸ˜” Thanks @shiena for the workaround!
Has anyone found a way to display the more modern UI?

This repo seems to have last been updated over 6 years ago... Are we hopeful that there's even a remote chance that this gets fixed?

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024

@MadStark
The AutoUpdateEnabled property is required to use the modern UI, but is not supported in the mono version.
#135 (comment)
Therefore, we need to call the native API, but unfortunately there is no workaround because the COM call causes an error.

from unitystandalonefilebrowser.

MadStark avatar MadStark commented on June 15, 2024

With the Mono System.Windows.Forms, I have the issue of Unity editor crashing whenever I close it after using the old window UI. Do you have the same thing?

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024

@MadStark
Try copying Mono.Posix.dll and Mono.WebBrowser.dll to the Plugins folder with reference to #76 .

from unitystandalonefilebrowser.

MadStark avatar MadStark commented on June 15, 2024

@shiena Thanks! Unfortunately it didn't fix my issue... I think it might be interfering with other things in my project. After I open the browser, next time I will close Unity, it will crash instead!
I'll do some digging!

from unitystandalonefilebrowser.

shiena avatar shiena commented on June 15, 2024

I took some pull requests and repackaged them as upm.
https://github.com/shiena/UnityStandaloneFileBrowser

from unitystandalonefilebrowser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.