Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

System.Windows.Forms in Unity

Discussion in 'Scripting' started by S_P_S, Jun 29, 2016.

  1. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Hello,

    I want to open an OpenFileDialog through my Unity game. I added the System.Windows.Forms DLL into a Plugins folder and everything works fine in the editor.

    But Unity doesn't allow me to build my application with the System.Windows.Forms DLL.

    It seems that there are two different System.Windows.Forms DLLs, an original windows one and a mono one which seems to not have the FileDialog thing included.

    Why can't I build my game with the System.Windows.Forms DLL and why has the mono System.Windows.Forms DLL the FileDialog system not included?

    best regards
     
  2. Henning_Justare

    Henning_Justare

    Joined:
    Nov 10, 2014
    Posts:
    21
  3. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Thanks for your answer!

    I am using .net not .net subset already.

    The problem is that OpenFileDialog is for some reason not supported.
     
  4. Henning_Justare

    Henning_Justare

    Joined:
    Nov 10, 2014
    Posts:
    21
  5. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    But that's the thing. I need the windwos one, not a custom one.

    It only works if I build with the mono System.Windows.Forms DLL and after the build I replace that one with the Windows System.Windwos.Forms DLL. Then everything works, but I don't want to do it that way.
     
  6. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    This is unsupported and will most likely result in your application not running or simply crashing on any platform other than Windows. Why can't you use a GUI made with Unity to do the same thing?
     
    Henning_Justare likes this.
  7. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Because in my opinion it's not a good user experience if you have a custom file browser and not the OS one.
    BTW: It only has to work on widows.
     
    Andersen_27 likes this.
  8. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    802
    Why not just replace the DLL after building? From what I remember is it not just a 5 second step? If this is the solution but you have to replace the DLL after building just stick with that. From reading this thread there is no other option unless you build your own.
    This thread is basically done anyhow.
    Option 1: Replace the System.Windows.Forms DLL in the build with another.
    Option 2: Create your own using the GUI System.
     
  9. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Yes you are right, but I don't know, which side effects the DLL replacement has. Maybe someone can tell me where the different between these two DLLs is.

    best regards
     
  10. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    7,252
    One is the Microsoft implementation, the other is the Mono implementation. Their interfaces are meant to be the same, so all classes and method names and what not should line up.

    I don't think unity cares about the signing on the dll, so it probably won't freak out.

    Try replacing it, if it doesn't crash your game, you'll be fine. The only issue I can see happening if you swap it is that the mono runtime checks the assembly domain signature and freaks out because it changed... which like I said, you'll know right away, your game just won't work.

    And if that happens, will have to find another route of doing it.

    Well, considering that mono is open source, anyone who looks into the source code knows what it needs and how it works:
    https://github.com/mono/winforms


    ...

    Back @OP - I'm also willing to bet the reason it's missing from the mono implementation of WinForms is because we have an older version of it. Try using a newer version of the mono one if the previous option doesn't work.
     
  11. Polci

    Polci

    Joined:
    Apr 8, 2015
    Posts:
    1
    Hi, I figured it out and it works so far so good. Building throws an unsupported warning, but seem that it does not matter. What I did:
    - Set the library from .NET 2.0 subset to .NET 2.0.
    - Copy the System.Windows.Forms and System.Drawing to the plugins folder. Note that you must use the Mono ones (can be found in somewhere deep in unity installation folder). .NET ones do not work (if I remember correctly, they worked in the editor but could not build).
    - Then I use the Visual Studio to make the desired .NET code for me and then just copy it to my MonoBehaviour script.
     
    Last edited: Sep 10, 2016
  12. Sir-Thorgeir

    Sir-Thorgeir

    Joined:
    Jan 17, 2013
    Posts:
    16
  13. SHAILAN

    SHAILAN

    Joined:
    Jun 3, 2019
    Posts:
    1
    Try changing the Api compatibility Level from .NET Standard 2.0 to .NET 4X.
    This Solution worked from me
    I'm using Unity 2018.3.5f1.
    Check the attached image for reference
    browse.JPG
     
  14. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
    changing to net 4x didn't work for me building with il2cpp
     
unityunity