
WasmWinforms – .NET WinForms in a browser - yread
https://github.com/roozbehid/WasmWinforms
======
shawnb576
I was one of the main engineers on Windows Forms circa 1998-2005. This blows
my mind in so many ways.

~~~
DaiPlusPlus
Off-topic: but why did they opt for Windowed (hWnd’d) controls for WinForms
when VB6 seemed fine with windowless controls and while there are advantages
to windowed-controls (e.g. getting the latest enhancements to Common Controls)
it seems WinForms defaults to using older versions and still overrides things
like painting events. Almost as if WinForms couldn’t tell if it wanted to be
like AWT or more like WxWidgets.

~~~
ygra
Didn't VB use windowed controls as well? I distinctly remember everything
being a ThunderSomething when looking with Spy++.

~~~
DaiPlusPlus
VB (1-6)’s “built-in” controls like Buttons and Checkboxes were windowless,
most of the others were ActiveX controls which were windowed. This carried-
over to VBA where some controls are windowless built-ins and the rest are
ActiveX too.

~~~
pjmlp
VB 1 - 4 used VBX controls implemented in C, only with VB 4 came the support
for COM (aka ActiveX, aka subset from OLE 2.0).

------
dvt
Calculator example breaks when attempting to divide by zero:

    
    
        Uncaught abort(20) at Error
            at jsStackTrace (https://webassembly.z19.web.core.windows.net/Calculator/mono.js:1063:12)
            at stackTrace (https://webassembly.z19.web.core.windows.net/Calculator/mono.js:1077:11)
            at abort (https://webassembly.z19.web.core.windows.net/Calculator/mono.js:18097:43)
            at nullFunc_ii (https://webassembly.z19.web.core.windows.net/Calculator/mono.js:14694:2)
            at b20 (wasm-function[10723]:31)
            at emterpret (wasm-function[922]:12351)
            at _do_icall (wasm-function[8343]:63)
            at emterpret (wasm-function[922]:7917)
            at _interp_exec_method_full (wasm-function[7977]:65)
            at emterpret (wasm-function[922]:7129)
    

Which is weird, because in the actual code[1], there's a division by zero
check which should pop up a message box:

    
    
        case '/': 
            if (opr2 != 0) 
            { 
                result = (opr1 / opr2).ToString(); 
            } 
            else 
            { 
                MessageBox.Show("Can't divide by zero"); 
            } 
            break; 
    

Given a closer look, I doubt this is a WasmWinforms bug, but rather mono-wasm
(or somewhere else along the compilation pipeline).

Edit: I'm wrong, it's a WasmWinforms bug.

[1] [https://code.msdn.microsoft.com/windowsdesktop/Simple-
Calcul...](https://code.msdn.microsoft.com/windowsdesktop/Simple-
Calculator-54ec8e4a)

~~~
hokkos
Maybe the problem is the MessageBox method.

~~~
dvt
Given an even closer look, you're right ;) I saw MessageBox here[1] and
assumed the implementation would just go through. After all, why would all
other components compile fine, except for MessageBox? But actually, it even
logs in the console

    
    
        dl_mapping_symbol MessageBox - proc name MessageBox not matched
    

So yep, MessageBox has no matched symbols so it crashes and burns.

[1]
[https://github.com/roozbehid/WasmWinforms/blob/master/winfor...](https://github.com/roozbehid/WasmWinforms/blob/master/winforms/external/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MessageBox.cs)

------
dvh
ERROR>
[https://webassembly.z19.web.core.windows.net/Calculator/mono...](https://webassembly.z19.web.core.windows.net/Calculator/mono.js\(1181\)):
Uncaught RangeError: WebAssembly.Memory(): could not allocate memory

~~~
amaccuish
I got RangeError: bad Memory initial size

~~~
adzm
Calculator demo uses around 1.5gb of memory so I wouldn't be surprised if it
runs into various memory pressure issues.

~~~
dvh
That explains it as I have only 512MB.

~~~
leeman2016
Wow. Is that a VM or an actual PC?

~~~
dvh
Mobile

------
kmote00
From the ReadMe: "There are many many bugs and this project/product is not at
all recommended for production. It is pre-alpha phase!"

------
AdeptusAquinas
THE CYCLE IS COMPLETE!

More seriously, looking forward to when CLR can compile down to web assembly
directly rather than requiring a large runtime. Baby steps.

~~~
kej
This is one of the targets of the CoreRT project, and a very limited version
of it works today.

------
brian_herman__
[https://www.destroyallsoftware.com/talks/the-birth-and-
death...](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-
javascript)

~~~
bsaul
i saw that video in the past, but watching it again now took me 15 minutes to
realize this was supposed to be a fun video about an absurd future.

------
dare0505
Wow, does this mean that (in the near future) we'll be able to take that HUGE
repository of WinForms apps and port them to the web? Would be exciting...

~~~
int_19h
They will run, but of course the WinForms UI is not exactly optimized for
mobile (even high DPI support is patchy).

------
jijji
I gave up after five minutes with a screen that said "Loading...". Any reason
why <textarea> was thought to be so inefficient?

------
nly
Similar to Qt for WebAssembly:

[http://example.qt.io/qt-
webassembly/widgets/richtext/textedi...](http://example.qt.io/qt-
webassembly/widgets/richtext/textedit/textedit.html)

~~~
mbel
And somehow it's more snappy and responsive than some of the pages that are
done in HTML today, amazing.

------
tomduncalf
WebAssembly is amazing technology and in my experience is already pretty
mature and can do incredible things. Definitely worth taking some time to
understand it I think, especially if you have experience with “non-web”
languages like C/C++. I thought Lin Clark’s cartoon intro was excellent:
[https://hacks.mozilla.org/2017/02/a-cartoon-intro-to-
webasse...](https://hacks.mozilla.org/2017/02/a-cartoon-intro-to-webassembly/)

------
croddin
That is really cool that that is possible! Could the same approach be used for
WPF? How do WinForms and WPF differ at that layer? Would WPF be a lot bigger
of a project than WinForms?

~~~
pjmlp
Kind of, Uno allows for UWP on WebAssembly.

[https://platform.uno/](https://platform.uno/)

Yes I know it isn't the same XAML.

~~~
ygra
Well, it _is_ the same XAML, it just uses different controls from a different
namespace. At its heart XAML is just a way of encoding object graphs in XML
and can work with pretty much anything that has a default ctor and properties.
As far as generic serialization formats for XML go it's one of the nicer ones
in my book.

~~~
pjmlp
My opinion as well, the side remark as oriented towards those that always
complain about WPF, Silverlight, UWP and Xamarin XAML being a bit different,
when they actually share the same underlying concepts anyway.

------
jmkni
Now we just need to embed this in an MVVM WPF application!

------
_underfl0w_
Am I the only one worried about how much easier this might make it to trick
our less-tech-savvy friends into thinking their device "has a virus"? Might be
enough to confuse my parents, at least.

~~~
untog
It's just rendering to a canvas tag so it's not doing anything you can't
already do in a browser (and haven't been able to do for years)

------
miguelrochefort
A similar project is Uno. It lets you run UWP apps on iOS, Android and
WebAssembly.

[https://github.com/nventive/Uno](https://github.com/nventive/Uno)

------
asien
The more WASM projects are being released , the more I’m telling myself that
WASM has nothing to offers to regular JavaScript developers.

Solutions like this have already existed and still exist today. ASP.NET
Webforms was basically the same attempt as this but with HTML5 base controls.

Running .NET on the browser was a great idea on paper for cross-platform
application , but seing how much time it takes to load the entire .NET
framework it’s just isn’t a suitable solutions for production.

~~~
manigandham
This isn't a real project, it's just an experiment.

Blazor is the official Microsoft project that uses a small .NET runtime with
Razor components and is already smaller and faster than many JS bundles
without any optimizations.

------
bdcravens
So ActiveX (or its offspring) in the browser is apparently back :-)

On a positive note, as I watch the assemblies load, Angular sites with 50k or
so npm packages doesn't seem so heavy :-)

~~~
raisedbyninjas
ActiveX has never left IE (not Edge). Although Microsoft patches have broken
it a few times. So you can run Winforms in the browser on a full Microsoft
supported stack for the time being.

------
vedantroy
Something I've wondered about with Web Assembly applications is, how do I
actually view the web assembly/compiled blob? E.g--with normal Javascript, I
can go to "sources" tab in developer tools and download all the JS, but how do
I download the wasm?

Am I misunderstanding how web assembly works?

~~~
testvox
If you are using a fairly new version of chrome any wasm should indeed show up
under sources, under a special wasm domain. It looks like this
[https://webassemblycode.com/wp-content/uploads/Chrome-
Wasm-D...](https://webassemblycode.com/wp-content/uploads/Chrome-Wasm-Debug-
WasmView.png)

It doesn't show the source file because the browser is not actually aware of
where the js on the page got the wasm its running from. From the browser's
perspective it just fetched an opaque file and then separately got told to run
some wasm.

You can see the actual source file for the wasm for one of the demos here, it
still shows up in the network tab (but for example if the js on the page
generated the wasm then it wouldn't).
[https://webassembly.z19.web.core.windows.net/mono.wasm](https://webassembly.z19.web.core.windows.net/mono.wasm)

------
tyfon
Am I the only one that reads "Watcom assembler" when I see WASM? :)

In any case, it's pretty insane what they do now but I sort of fail to see how
W(eb) assembly is different from let's say a Java applet?

It is not native code is it?

------
krob
That thing is glitchy as F. My machine used almost 1.5gb of ram running that
thing. Couldn't barely drag the window or click any buttons, and froze my
mouse cursor.

------
catmanjan
Does anyone have an example/list of popular applications that use .NET
WinForms? The only ones I can think of are bespoke...

------
josteink
I wonder at what point Apple is going to add wasm-support to iOS.

It’s starting to feel quite left behind at this point.

~~~
comex
Just tested, and this demo runs fine on iOS. It's kind of funny to use a
classic Windows-style interface on a touchscreen. Loading time needs work,
though.

~~~
josteink
Might be a ram thing. I tested on my iPhone SE and even while waiting a long
time, it didn't seem to provide any visible results.

Edit: Trying it in Firefox desktop it fails too[1], so obviously this is not
really fully cross-browser compatible yet.

[1] RangeError: bad Memory initial size mono.js:1181:26

<anonymous>
[https://webassembly.z19.web.core.windows.net/Calculator/mono...](https://webassembly.z19.web.core.windows.net/Calculator/mono.js:1181)

​

~~~
comex
Makes sense. According to other comments in the thread [1] the page requests a
wasm heap of 1.25 GB (...hopefully unnecessarily!), while the iPhone SE has
2GB of RAM total, so it's easy to imagine that the remaining amount isn't
enough for both other allocations in Safari and other processes. I tested it
on my iPhone X which has 3GB of RAM – not that much more, but apparently
enough.

[1]
[https://news.ycombinator.com/item?id=18983109](https://news.ycombinator.com/item?id=18983109)

~~~
zozbot123
> the page requests a wasm heap of 1.25 GB

Par for the course in the "modern Web"

------
jug
Well now this was an unexpected early UI API for Web Assembly.

------
skocznymroczny
Why does it look like Windows 95?

