I am unable to get a GTK# app to run on windows, and I would appreciate any help I can get. I tried googleing around, but was unable to find a solution for my problem.
I wrote a small app in monodevelop using GTK#, which just opens a window with a button.
It runs fine on linux.
However I am unable to get it to run on windows.
I tried installing the GTK+ and the GTK# redistributables, the GTK# SDK, but it still does not work. And it does not show any exceptions thrown (in the command line), which would be helpful for debugging the problem.
After invoking the .exe, it sits there for a few seconds, and after that the shell reappears waiting for the next command, no output whatsoever.
Can anyone please walk me through what do I have to install on a virgin windows install to be able to run GTK# applications?
[edit] I understand mono is not needed to run them, and would like to avoid it, if possible.
Mono.Posix is a required part of the GTK# system - it contains the gettext library interface used to handle internationalized text. By writing in MonoDevelop, there is an option to allow internationalized text when creating the GUI interfaces, which will automatically call this library as part of the generated Build function (it seems to be called when setting user-displayed text, like the title of your form). This means you only need the Mono.Posix.dll library (which will work on Microsoft .NET), not the full Mono runtime.
The exception may be getting written to stderr instead of stdout, which the Windows command line does not show by default. Try:
myapp.exe 2> my.log
and see if that writes the error to a logfile called my.log.
Much like you I had an issue running on Windows 10. The issue in my case was resolved after another Google Result to a blog which mentions that the Mono.Posix references are indeed the cause. However, the blog indicated that you must also delete/convert global::Mono.Unix.Catalog.GetString (if you are using MonoDevelop's Stetic GUI creator). Those will be usually on your Labels.
ie:
dev#laptop:/tmp/myproject$ rg "global::Mono.Unix."
96: this.label2.LabelProp = global::Mono.Unix.Catalog.GetString("25 ROUNDS OF DEAF");
changes to
96: this.label2.LabelProp = "25 ROUNDS OF DEAF"
Since Stetic GUI creator usually puts Partial class files in the subfolder gtk-gui of the project directory. That's probably the best place to check for strays. Although ripgrep (the rg command used up there does recursive fast directory searching of all child folders so might as well use that)
After this you must install the GTKSharp Runtime for .NET (as of today it's file gtk-sharp-2.12.45.msi from mono-project.com for GTK+ also known as GTK2. GTK3 is different and it may be different for future Googler's)
After that recompile the application in MonoDevelop and you can run it on Windows
Source of steps: https://www.martyndavis.com/?p=432
Actually application can run without Mono (console apps, for example) on Windows, but if you have reference to Mono.Posix in code, it can use some platform-specific functions that couldn't be executed on Windows.
On Windows in MonoDevelop you can choose between frameworks (Mono or MS.Net). Try to recompile app on Win with MS.Net framework selected.
Related
I have a utility editor application that goes with another main application. The main application is a Windows EXE usually, but there is also a Unix and a Mac version. This application was written by another company for us. It is not C#.
We have a utility editor program that works with the main application. The original version is a WinForms app, but it is showing it's age and some of the functionality no longer works on today's Windows. So the app is being rewritten in WPF with .NET Core 3.1, with the hope that maybe we will also compile it for Unix and Mac someday, if possible. They want it to be a stand-alone app so it can more easily be used by students at different universities and other organizations. Click-Once, MSIX, and copying larger folders are not options. They want a standalone EXE(s) they can upload/distribute for 32 and 64 bit Windows initially, often sent on DVD.
But I am having build issues for WPF. I have tried to publish the app, and the VS Installer add-on, but they were failures, which appears to be the common complaint on the internet. For some reason, you always end up with a DLL application instead of an EXE, and it doesn't run and I am not alone per the discussions on the internet. I am thinking is has something to do with the .NET Core but I just don't know enough about it to know how to resolve it. One article hinted that the DLL might be the portable part, and then you need a platform specific module that runs it??? Did I misunderstand that? If so, How do I create one?
I am now looking into third party tools. It appears Wix might be worth exploring, but the learning curve is billed as large, so the boss is nervous. I am also not sure about the Unix or Mac builds. Will those be different tools yet again?
According to this it probably is, but this is 2 years old:
How to build installers for .NET Core app?
Has anyone been successful in building a WPF .NET Core 3.1 setup.EXE that actually installs a usable application? If so, what tools did you use? Can you provide any advice for what I might be missing? I can get the setup.exe, but the app that it installs is not usable.
I would be ever so grateful for any help you can provide. This community has been SOOO helpful to me for many years and I can usually find the answer from previous questions without ever asking anything myself. So I have no rating. But I have been a user for over 10 years! Please don't hold that against me? But this time I am stumped. It could just be I am tooo new to .NET Core (first app in it) and I don't have the right search terms. I am usually a Web developer. But Web is not an option here.
Thank you for your consideration,
MLY
A bit late, you might have already figured out a solution, but for anyone else wondering.
One way is to use ClickOnce.
If using Visual Studios, you should be able to right click your main project and select "Publish". Then you should be able to click "New" publish profile. From the options that come up you can either select "ClickOnce", and then you should be presented with some settings. For you, most importantly, would be two of those tabs, "Install location" and "Configuration". In the former you can choose "From cd/dvd, or usb" since you mention that is a method of delivering the executable you will need.
And in the latter, you can select "Deployment mode" to be "self-contained", and under "File-publish options" choose "Produce single file".
This should ultimately produce an EXE for your application that can be used as a standalone.
Note that using VS19 there are some issues that seem to not allow this to happen https://github.com/dotnet/sdk/issues/11351
However using VS22 this does not seem to be an issue, I at least have not experienced it there.
For more information
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/deploying-a-wpf-application-wpf?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/visualstudio/deployment/quickstart-deploy-using-clickonce-folder?view=vs-2022
Also, F.Y.I, WPF applications only run on windows, so you wont be able to deploy them on Mac or Unix at all. There is some community support for using Xamarin.Forms with WPF, but if you need multi-OS deployment you should not start developing this application with WPF in the first place.
I'm using VS2019 under Windows 10 and I'm trying to figure out how to compile for the non-Windows platforms. I'm aware that only some languages support cross-compilation (C# being one of them). So I decided to start off with one of Microsoft's own examples (the Console App for .NET Core). When asking VS2019 to create the Console project, it shows me various image icons which suggest that it'll be buildable for Windows, Linux and macOS - but no matter what I do, I can only make it build the Windows target.
After a bit of research I realized that I need to add this line to my C# project file:-
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
but even after adding that line (and re-loading / re-building the project) it staunchly refuses to build anything apart from the Windows target. Over on CodeGuru, one of the devs there tried it for me (under VS2017) and managed to make it work - but I've tried it in VS2019 and also VS2015 and I can't make it work in either of them. Any ideas what I might be doing wrong??
[Edit...]
Thanks Magnetron - if I press Build->Publish I see a totally different dialog from the one you're seeing (and it's the same in both VS2015 and VS2019):-
Even if I follow the Next or Finish buttons I never see the Create Profile option :(
Go to Build > Publish, select Folder and click on Create Profile
Then Click on Edit and change the Deployment Mode to Self-contained. At last, you can specify the target OS in Target Runtime
You can create multiple profiles for each OS, and publish each one individualy as needed.
Edit:
The posted publish dialog is for a .Net Framework Console app, not an .Net Core one. The .Net framework is Windows only, you have to create your project as a .Net Core
Woohoo!! I just ran the VS2019 installer to remind myself how to uninstall (in preparation for tomorrow) and it told me there's already a 16.3.5 available. 16.3.4 only got installed a few hours ago but for the hell of it, I figured I might as well try the newer version - and it's now working !!!
So it's basically as stated in the title. I've created a WPF app in Visual Studio 2013 using some external libraries.
Application works flawlessly on my Development machine (Windows 8.1 x64 + Visual Studio 2013) but doesn't run at all on Production device (Tablet with Windows 8 (NOT 8.1)). App is developed under .NET 4.5, doesn't matter if I try to run Debug or Release version. The proccess just hangs a while and then closes without any errors or messages.
If anyone would know what to do or how to fix this I would be very happy.
Thanks in advance :).
The first thing too look up in this situation, would be the Windows event log. When a .NET application crashes badly, the .NET Runtime will log an event there.
Most of the time, these events will log the stack trace which lead to the crash. This will give you a hint as to what happened.
Such logs are found in the "Application" category, and the source name you need to look for is ".NET Runtime". Usually, there will be another entry with the source name "Application Error", but this one is much less likely to help you.
Another useful technique, is to add a Console.WriteLine call at the start of your program, in order to see if that line gets to run at all.
Depending on what you find using these techniques, you may also want to use tools such as Dependency Walker or ILSpy, as suggested by Mike Dinescu.
Most likely a binding error occurs at start-up but the production machine you're testing on is configured to silently report these errors and it doesn't display the typical dialog box that would inform you that the process crashed.
Don't fret though, that message would probably not help you too much anyway.
What you need to do is inspect the main executable with a tool that can generate a dependency tree and figure out which DLLs are missing. Most likely these will be native binaries, not managed. The usual suspects are the VC runtime, or MFC or ATL libraries but there could be others too. That's why you need to use a tool such as DependencyWalker or RedGate's Reflector to find all dependencies for the main executable.
It is because your external libraries are not compiled into final .exe file. So you either need to include them in the same folder or merge them into exe but this process can be quite tricky. Look for ILMerge. However it is way easier to just copy them with your exe file.
I wrote a C# program and I will compile like this:
C:\Users\Administrator\Documents\Visual Studio 2005\Projects\GUITest\GUITest>mcs *.cs /r:System.Data,System.Drawing,System.Windows.Forms,..\HtmlAgilityPack.dll
But the output application has a console window.
Is there a way to compile the program so that I can get a application without a console window?
There are two different "modes" or types of Windows applications: console applications and GUI applications. The same goes for managed applications, regardless of how you build them.
Console applications will always display a console window on startup, automatically. You can also write code to display a GUI window (e.g., a form), but this is optional. Either way, the console window will always be displayed.
GUI applications do not display anything on startup. Generally, you write code that displays a GUI window (e.g., a form), but you do not have to. If you do not display anything, you have created what people often refer to as a "background application" because it runs in the background without displaying any UI. That is not possible with a console application, because it displays that ugly console window.
So if you don't want the console window, you don't want a console application. You want a regular GUI application.
Now, the challenge is figuring out how to achieve this using the Mono compiler. Visual Studio exposes this option as a project-level setting. The Mono compiler needs a flag, /target to tell it what type of application to build.
/target:exe (the default option) will build a console application
/target:winexe will build a GUI application
/target:library will build a library (which is not an executable application, but just a chunk of reusable code)
So, change the command you're running at the command line to:
mcs *.cs /target:winexe /r:System.Data,System.Drawing,System.Windows.Forms,...
I believe that you will also need to make sure that you're running a relatively recent version of Mono. The older versions did not include support for creating GUI applications (the /target:winexe switch was not implemented). I know that this is fully supported as of version 2.8, but there's little reason not to use the latest version available.
In case my answer is not authoritative enough for you, you'll find the same quick fix (without the rationale) documented in the Mono WinForms FAQ.
I installed MonoDevelop on Linux and wrote a shell GTK+ application. When I compile and run the application shows up correctly in Linux. When I move the .exe over to Windows, I get a crash "Windows Not Responding", so there is no stack trace. Then I figured I had to install Mono For Windows, so I did that, but no luck - I still crash.
More generally, I am having a hard time picturing what is going on here. Please disabuse me of whatever I get wrong:
People who started the Mono project wrote their own compiler (likely from scratch) to compile C# code. They modeled this after looking at the .NET Framework
They also wrote a CLR for their mono implementation of the byte code. Any architecture that wants to run this code will need the Mono Runtime, as only the Mono Runtime can run the code.
Do I have it right? Why doesn't my program run? Thanks in advance.
Three things stand out to me:
GTK+. GTK isn't part of windows or mono on windows by default. You must install it separately.
Shell Application. That means something special in the windows world (an app that runs as part of (extends) the windows desktop shell, rather than as it's own program), and I wouldn't be at all surprised to hear that these don't work cross platform very well or even at all. I'd assume you mean "Console Application" instead, but then why the need for GTK+?
Mono. Make sure you invoke the program using mono. Just because mono is installed doesn't mean that's how your program will run vs Microsoft's own .Net implementation.
Hey, I'm only vaguely familiar with Mono myself but I -think- there is an analyzer tool that will show possible portability issues. If you run through that does it show any issues?
Few things you also check.
Is mono installer contains GTK# libraries.
If yes, check that is the assemblies are in GAC. The assemebiles names be gtk-sharp.dll, gdk-sharp.dll
If no, copy the referenced assemblies in your bin directory. you can see that in your mono develop project.
I assume you mean you wrote a GTK# application. In that case, to run it on Windows, you need to make sure you install "GTK# for .NET" from the Mono Downloads page
On Windows, you can capture a crash dump and see what causes the crash. For example, use WinDbg to execute this application.
http://www.microsoft.com/whdc/devtools/debugging/default.mspx