Mention Windows Bash? #199

Closed
turbo opened this Issue Apr 14, 2016 · 19 comments

Comments

Projects
None yet
7 participants
@turbo
Contributor

turbo commented Apr 14, 2016

Windows 10 recently received Bash. This is made possible through a Ubuntu subsystem, which means commands executed in bash (bash.exe instead of cmd.exe) will run in the Ubuntu context. Since APT is enabled, Mono installation works.

I tested this on Windows 10 Enterprise (non-LTSB), Build 14316.1. These are the commands I used:

Installing Mono

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Works as expected, no warnings/errors.

sudo sh -c 'echo "deb http://download.mono-project.com/repo/debian wheezy main">>/etc/apt/sources.list.d/mono-xamarin.list;apt-get -qq update;apt-get -qq install git gcc mono-complete'

No warnings / errors. Known issues:

  • APT likes to get stuck in Windows Bash (waiting for headers). Rerunning the command will fix this.
  • APT complains about systemd et al. This can be safely ignored.

Both these issues are unrelated to Mono and don't have any impact on Mono or it's components as far as I can tell.

Testing

As a trivial test, I compile Turbo from source. This will test Mono, XBuild and mkbundle:

sudo sh -c "git clone http://github.com/turbo/src;cd src;xbuild *.sln /v:q;cp *.dll /usr/lib/;mkbundle -o /usr/bin/turbo *.exe;cd .."

Compiles fine:

XBuild Engine Version 12.0
Mono, Version 4.2.3.0
Copyright (C) 2005-2013 Various Mono authors
/usr/lib/mono/xbuild/12.0/bin/Microsoft.Common.targets:  warning : Reference 'System.ComponentModel.Composition.Registration' not resolved
OS is: Linux
Sources: 1 Auto-dependencies: False
   embedding: /root/src/turbo.exe
Compiling:
as -o temp.o temp.s
cc -ggdb -o /usr/bin/turbo -Wall temp.c `pkg-config --cflags --libs mono-2`  temp.o
Done

Let's run the tests:

root@localhost:~# ls
src
root@localhost:~# turbo src/Tests/tests.js -o ./foobar.exe
Warning in file <src/Tests/tests.js> at (80,6): (TC1187) Variable might be uninitalized.
Warning in file <src/Tests/tests.js> at (407,9): (TC1187) Variable might be uninitalized.
root@localhost:~# mono foobar.exe
> Tests passed: 980/980
> Tests failed: 0/980
> Total time:   309 ms

Splendid. Everything works as one would expect. The only thing that doesn't work (yet) is the binfmt integration, i.e. mono foobar.exe will succeed, but ./foobar.exe will fail. This contradicts the default behavior in Ubuntu, but IMO this is a minor issue.

Adding a hint

My suggestion: Adding a hint somewhere, either on the install page for Windows or Linux that Mono also works in Windows Bash.

Personally, I find this to be quite exciting, as one can now have Mono running both natively on Windows and in the Ubuntu subsystem.

@akoeplinger

This comment has been minimized.

Show comment
Hide comment
@akoeplinger

akoeplinger Apr 14, 2016

Member

Given that this feature is only in the current insiders preview and it's totally unsupported at this point (though awesome that Mono just works!) I don't want to put a prominent note on the download page.

We can certainly add a note at the bottom of the Windows install page with a link to this GitHub issue though :) Want to send a PR?

Member

akoeplinger commented Apr 14, 2016

Given that this feature is only in the current insiders preview and it's totally unsupported at this point (though awesome that Mono just works!) I don't want to put a prominent note on the download page.

We can certainly add a note at the bottom of the Windows install page with a link to this GitHub issue though :) Want to send a PR?

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Apr 14, 2016

Contributor

We can certainly add a note at the bottom of the Windows install page with a link to this GitHub issue though :) Want to send a PR?

Done ;-)

Contributor

turbo commented Apr 14, 2016

We can certainly add a note at the bottom of the Windows install page with a link to this GitHub issue though :) Want to send a PR?

Done ;-)

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Apr 15, 2016

Contributor

Addendum 1: Set up a X server for Windows Forms

Yes. It is indeed possible to run (Mono) GUI applications in Windows Bash. All you need is a X server on the native-Windows side. I used Xming for this. You can install Xming without PuTTY, since you don't need a SSH client anymore - just use bash's SSH.

After installing and starting your X server do this:

  • Enable the X server on system start using Windows' Autostart
  • Spawn a new bash instance and nano your ~/.bashrc
  • Add export DISPLAY=:0 at the bottom of this file, write and exit nano
  • Either restart bash or source your bashrc

That's it. I've tested it using this simple boilerplate Form:

nano gui_test.js

Code:

import System;                                             
import System.Windows.Forms;                               
import System.Drawing;                                     
import Accessibility;                                      

class MonoBashGUITest extends Form {
  var btn : Button;                                  

  function MonoBashGUITest() {                       
    btn = new Button;                          
    btn.Text = "Fire Event";                   
    Controls.Add(btn);                         
    btn.add_Click(FoobarEvent);                
  }                                                  

  function FoobarEvent(sender, e : EventArgs) {      
    MessageBox.Show("Boom! Event was fired!"); 
  }                                                  
}                                                          

Application.Run(new MonoBashGUITest);                      

Compile and run:

turbo gui_test.js -s w
mono gui_test.exe

And it works:

xming

This is only a very basic test, but you shouldn't run into any problems with more complex Windows Forms applications.

Contributor

turbo commented Apr 15, 2016

Addendum 1: Set up a X server for Windows Forms

Yes. It is indeed possible to run (Mono) GUI applications in Windows Bash. All you need is a X server on the native-Windows side. I used Xming for this. You can install Xming without PuTTY, since you don't need a SSH client anymore - just use bash's SSH.

After installing and starting your X server do this:

  • Enable the X server on system start using Windows' Autostart
  • Spawn a new bash instance and nano your ~/.bashrc
  • Add export DISPLAY=:0 at the bottom of this file, write and exit nano
  • Either restart bash or source your bashrc

That's it. I've tested it using this simple boilerplate Form:

nano gui_test.js

Code:

import System;                                             
import System.Windows.Forms;                               
import System.Drawing;                                     
import Accessibility;                                      

class MonoBashGUITest extends Form {
  var btn : Button;                                  

  function MonoBashGUITest() {                       
    btn = new Button;                          
    btn.Text = "Fire Event";                   
    Controls.Add(btn);                         
    btn.add_Click(FoobarEvent);                
  }                                                  

  function FoobarEvent(sender, e : EventArgs) {      
    MessageBox.Show("Boom! Event was fired!"); 
  }                                                  
}                                                          

Application.Run(new MonoBashGUITest);                      

Compile and run:

turbo gui_test.js -s w
mono gui_test.exe

And it works:

xming

This is only a very basic test, but you shouldn't run into any problems with more complex Windows Forms applications.

@txdv

This comment has been minimized.

Show comment
Hide comment
@txdv

txdv Apr 15, 2016

Contributor

I'm not sure if I'm excited about this or confused (windows forms on X on windows)

Contributor

txdv commented Apr 15, 2016

I'm not sure if I'm excited about this or confused (windows forms on X on windows)

@lextm

This comment has been minimized.

Show comment
Hide comment
@lextm

lextm Apr 17, 2016

Contributor

@txdv it should be Windows Forms on Mono/X on Ubuntu on Windows 10. Well it bloats my mind.

Contributor

lextm commented Apr 17, 2016

@txdv it should be Windows Forms on Mono/X on Ubuntu on Windows 10. Well it bloats my mind.

@turbo turbo referenced this issue in ethanhs/WSL-Programs May 31, 2016

Merged

Add Mono #18

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Jun 21, 2016

Contributor

Build 14367

There's a problem with mkbundle on WSL running on Build 14367. Not all of my tests succeed. Either there has been a change in Mono or in WSL. I'm investigating.

To reproduce (clean WSL, no gcc, mono or git):

wget -qO- git.io/ubuntu.sh|sh
turbo

Trace:

Error: No managed allocator, but we need one for AOT.
Are you using non-standard GC options?

Stacktrace:

  at <unknown> <0xffffffff>
  at System.Runtime.Remoting.Contexts.Context..cctor () <0x00014>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0x00062>

Native stacktrace:

        /usr/lib/libmonosgen-2.0.so.1(+0xdac0d) [0x7f087eb1ac0d]
        /lib/x86_64-linux-gnu/libc.so.6(+0x36cb0) [0x7f087e6a6cb0]
        /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7f087e6a6c37]
        /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7f087e6aa028]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c189) [0x7f087ecac189]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c397) [0x7f087ecac397]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c442) [0x7f087ecac442]
        /usr/lib/libmonosgen-2.0.so.1(+0xc6170) [0x7f087eb06170]
        /usr/lib/libmonosgen-2.0.so.1(+0xc91f4) [0x7f087eb091f4]
        /usr/lib/libmonosgen-2.0.so.1(+0xcfefb) [0x7f087eb0fefb]
        /usr/lib/libmonosgen-2.0.so.1(+0xdccdd) [0x7f087eb1ccdd]
        [0x7fff0c15]

Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Contributor

turbo commented Jun 21, 2016

Build 14367

There's a problem with mkbundle on WSL running on Build 14367. Not all of my tests succeed. Either there has been a change in Mono or in WSL. I'm investigating.

To reproduce (clean WSL, no gcc, mono or git):

wget -qO- git.io/ubuntu.sh|sh
turbo

Trace:

Error: No managed allocator, but we need one for AOT.
Are you using non-standard GC options?

Stacktrace:

  at <unknown> <0xffffffff>
  at System.Runtime.Remoting.Contexts.Context..cctor () <0x00014>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0x00062>

Native stacktrace:

        /usr/lib/libmonosgen-2.0.so.1(+0xdac0d) [0x7f087eb1ac0d]
        /lib/x86_64-linux-gnu/libc.so.6(+0x36cb0) [0x7f087e6a6cb0]
        /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7f087e6a6c37]
        /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7f087e6aa028]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c189) [0x7f087ecac189]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c397) [0x7f087ecac397]
        /usr/lib/libmonosgen-2.0.so.1(+0x26c442) [0x7f087ecac442]
        /usr/lib/libmonosgen-2.0.so.1(+0xc6170) [0x7f087eb06170]
        /usr/lib/libmonosgen-2.0.so.1(+0xc91f4) [0x7f087eb091f4]
        /usr/lib/libmonosgen-2.0.so.1(+0xcfefb) [0x7f087eb0fefb]
        /usr/lib/libmonosgen-2.0.so.1(+0xdccdd) [0x7f087eb1ccdd]
        [0x7fff0c15]

Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Jun 25, 2016

Contributor

There's definitely something wrong here. I can repro this on WSL, Ubuntu and even Travis CI agrees. I'm also not the only one running into this issue.

It's a regression, the last working build is Mono 4.2.4. There are some less than helpful other bug reports about this. I've included them and the Travis Logs (contain stacktraces) in Bug No. 42169.

To repro on a clean Ubuntu system:

wget -qO- git.io/ubuntu.sh|sh
turbo

Or, if Mono is already installed:

sudo sh -c "git clone http://github.com/turbo/src;cd src;xbuild *.sln /v:q;cp *.dll /usr/lib/;mkbundle -o /usr/bin/turbo *.exe;cd .."
turbo

This seems to be a mkbundle issue, @akoeplinger, is there a bugtracker somewhere specifically for mkbundle, or is the above bug report sufficient?

Contributor

turbo commented Jun 25, 2016

There's definitely something wrong here. I can repro this on WSL, Ubuntu and even Travis CI agrees. I'm also not the only one running into this issue.

It's a regression, the last working build is Mono 4.2.4. There are some less than helpful other bug reports about this. I've included them and the Travis Logs (contain stacktraces) in Bug No. 42169.

To repro on a clean Ubuntu system:

wget -qO- git.io/ubuntu.sh|sh
turbo

Or, if Mono is already installed:

sudo sh -c "git clone http://github.com/turbo/src;cd src;xbuild *.sln /v:q;cp *.dll /usr/lib/;mkbundle -o /usr/bin/turbo *.exe;cd .."
turbo

This seems to be a mkbundle issue, @akoeplinger, is there a bugtracker somewhere specifically for mkbundle, or is the above bug report sufficient?

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Jul 4, 2016

Contributor

Regression Bug confirmed by others. Use Mono 4.2 as a workaround. Stay away from Mono 4.4 if you're going to use embedding at all.

See

Please take a look @akoeplinger, @alexrp, @vargaz (, @lambdageek ?). This applies to ubuntu/debian systems and affects multiple users.

Contributor

turbo commented Jul 4, 2016

Regression Bug confirmed by others. Use Mono 4.2 as a workaround. Stay away from Mono 4.4 if you're going to use embedding at all.

See

Please take a look @akoeplinger, @alexrp, @vargaz (, @lambdageek ?). This applies to ubuntu/debian systems and affects multiple users.

@turbo turbo referenced this issue in ethanhs/WSL-Programs Jul 4, 2016

Closed

Mono Issues #21

@akoeplinger

This comment has been minimized.

Show comment
Hide comment
@akoeplinger

akoeplinger Jul 4, 2016

Member

@minxomat Thanks, sorry for the delay. I think 42169 and 42058 are ultimately the same underlying problem. Please file any issues with Mono on Bugzilla, as this GitHub repo is only used for the website.

Member

akoeplinger commented Jul 4, 2016

@minxomat Thanks, sorry for the delay. I think 42169 and 42058 are ultimately the same underlying problem. Please file any issues with Mono on Bugzilla, as this GitHub repo is only used for the website.

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Jul 4, 2016

Contributor

Please file any issues with Mono on Bugzilla

I'm aware, I just needed a place to ping (and a point of reference for the WSL list) :-)

Contributor

turbo commented Jul 4, 2016

Please file any issues with Mono on Bugzilla

I'm aware, I just needed a place to ping (and a point of reference for the WSL list) :-)

@simonegli8

This comment has been minimized.

Show comment
Hide comment
@simonegli8

simonegli8 Aug 4, 2016

Just installed WSL, but I cant setup the mono apt-get repos.
When I try to setup the keys with
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

I get following error (looks like certificates missing?)
gpgkeys: HTTP fetch error 7: couldn't connect: Permission denied
gpg: No valid OpenPGP-data found

simonegli8 commented Aug 4, 2016

Just installed WSL, but I cant setup the mono apt-get repos.
When I try to setup the keys with
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

I get following error (looks like certificates missing?)
gpgkeys: HTTP fetch error 7: couldn't connect: Permission denied
gpg: No valid OpenPGP-data found

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Aug 5, 2016

Contributor

@simonegli8

Well, first off, that's not a mono error. Read the actual error description:

gpgkeys: HTTP fetch error 7: couldn't connect: Permission denied

Means your network config for apt is not setup correctly. Most likely cause for this is a proxy that is not setup correctly within bash or a mangled apt sources list. In any case, it's not related to Mono. Google the error and you'll get many threads troubleshooting this, e.g. this one.

I've just setup a WSL instance and tried the same:

key

Contributor

turbo commented Aug 5, 2016

@simonegli8

Well, first off, that's not a mono error. Read the actual error description:

gpgkeys: HTTP fetch error 7: couldn't connect: Permission denied

Means your network config for apt is not setup correctly. Most likely cause for this is a proxy that is not setup correctly within bash or a mangled apt sources list. In any case, it's not related to Mono. Google the error and you'll get many threads troubleshooting this, e.g. this one.

I've just setup a WSL instance and tried the same:

key

@simonegli8

This comment has been minimized.

Show comment
Hide comment
@simonegli8

simonegli8 Aug 5, 2016

You're right, it's not a mono error, I just wrote this here, because I was coming to this site when googling the error. I'm not behind a proxy, and this error happens on my machine on a fresh installed WSL. I don't get the error in my VirtualBox Ubuntu on the same machine.

You're right, it's not a mono error, I just wrote this here, because I was coming to this site when googling the error. I'm not behind a proxy, and this error happens on my machine on a fresh installed WSL. I don't get the error in my VirtualBox Ubuntu on the same machine.

@simonegli8

This comment has been minimized.

Show comment
Hide comment
@simonegli8

simonegli8 Aug 5, 2016

Uups, probably windows firewall.

Uups, probably windows firewall.

@simonegli8

This comment has been minimized.

Show comment
Hide comment
@simonegli8

simonegli8 Aug 5, 2016

Yep, it was my antivirus program's firewall.

Yep, it was my antivirus program's firewall.

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Aug 6, 2016

Contributor

@simonegli8 If in the future you have problems with Mono in WSL, I'd ask you to open an issue here and ping me.

Contributor

turbo commented Aug 6, 2016

@simonegli8 If in the future you have problems with Mono in WSL, I'd ask you to open an issue here and ping me.

@turbo

This comment has been minimized.

Show comment
Hide comment
@turbo

turbo Aug 6, 2016

Contributor

Also, Update:

WSL now fully supports X server communication. See above for how to setup an X server on the Windows side. That means (among other things), that you can now run any GUI ubuntu application. E.g. firefox, monodevelop, your favorite terminal etc.

Specifically you can now have completely separate monodevelop instances running (one on Windows, one on WSL), both at the same time. Linux applications and Windows applications can even access the same directory on disk at the same time.

Contributor

turbo commented Aug 6, 2016

Also, Update:

WSL now fully supports X server communication. See above for how to setup an X server on the Windows side. That means (among other things), that you can now run any GUI ubuntu application. E.g. firefox, monodevelop, your favorite terminal etc.

Specifically you can now have completely separate monodevelop instances running (one on Windows, one on WSL), both at the same time. Linux applications and Windows applications can even access the same directory on disk at the same time.

@morphx666

This comment has been minimized.

Show comment
Hide comment
@morphx666

morphx666 Apr 20, 2017

Followed the instructions to install mono and I can run console based applications without any problems, but trying to run a WinForms app yields the following error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentException: Value does not fall within the expected range.

Using Windows 1607 and mono (under WSL) version 4.8.1
I have attached both the complete output from mono as well as the sample code I'm using.

log.txt
gui.txt

morphx666 commented Apr 20, 2017

Followed the instructions to install mono and I can run console based applications without any problems, but trying to run a WinForms app yields the following error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentException: Value does not fall within the expected range.

Using Windows 1607 and mono (under WSL) version 4.8.1
I have attached both the complete output from mono as well as the sample code I'm using.

log.txt
gui.txt

@boxsnake

This comment has been minimized.

Show comment
Hide comment
@boxsnake

boxsnake May 29, 2018

Notes updated 2018.05.29

  • First: tip on apt-key
    When you are using sudo apt-key adv, if you see an error saying "IPC connect failed", reinstalling dirmngr in WSL will work.

  • Second: repo update note
    For latest Ubuntu 16.04 or Ubuntu 18.04 version with WSL, I think this repo should be:

# 16.04
sudo sh -c 'echo "deb http://download.mono-project.com/repo/ubuntu xenial main">>/etc/apt/sources.list.d/mono-xamarin.list;apt-get -qq update;apt-get -qq install git gcc mono-complete'

# 18.04
sudo sh -c 'echo "deb http://download.mono-project.com/repo/ubuntu bionic main">>/etc/apt/sources.list.d/mono-xamarin.list;apt-get -qq update;apt-get -qq install git gcc mono-complete'

Debian repo seems do not compatible with the latest WSL on Win10 1803.

The debian repo in first thread will give dependency unmet error when apt-get install called.

boxsnake commented May 29, 2018

Notes updated 2018.05.29

  • First: tip on apt-key
    When you are using sudo apt-key adv, if you see an error saying "IPC connect failed", reinstalling dirmngr in WSL will work.

  • Second: repo update note
    For latest Ubuntu 16.04 or Ubuntu 18.04 version with WSL, I think this repo should be:

# 16.04
sudo sh -c 'echo "deb http://download.mono-project.com/repo/ubuntu xenial main">>/etc/apt/sources.list.d/mono-xamarin.list;apt-get -qq update;apt-get -qq install git gcc mono-complete'

# 18.04
sudo sh -c 'echo "deb http://download.mono-project.com/repo/ubuntu bionic main">>/etc/apt/sources.list.d/mono-xamarin.list;apt-get -qq update;apt-get -qq install git gcc mono-complete'

Debian repo seems do not compatible with the latest WSL on Win10 1803.

The debian repo in first thread will give dependency unmet error when apt-get install called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment