"mono app.exe" gives error "File does not contain a valid CIL image." - mono

I've made the following as a simple test.
using System;
namespace test
{
class App
{
static void Main(string[] args)
{
Console.WriteLine("test");
Console.ReadLine();
}
}
}
Then compiled and moved the entire bin folder to my pi and tried to run it using "mono app.exe" but I get the error in the title. How do I run compiled .Net core executables using mono on raspberry pi?

Realized that mono is .NET framework.
I installed .NET core runtime and it worked.
I followed this guide

Related

VS2022 - Hot reload applying changes successfully but not reflecting in app for a simple console app

I have a simple .net 6.0 console with the following code running on visual studio 2022. I change the Console.WriteLine text while the app is running and I get a log message from hot reload saying "Changes were successfully applied.". But nothing happens on my app. What am I doing wrong? I tried with and without debugger as per suggestions on other stack overflow threads. But no luck it still does not work. Here's my code.
using System;
namespace TestVS2022
{
public static class Program
{
public static void Main(string[] args)
{
while (true)
{
System.Console.WriteLine($"Hello World.");
Thread.Sleep(1000);
}
}
}
}

Python.Net PythonEngine.Initialize() crashes application without throwing exception

My application (C#, VS2017) previously targeted Python 3.5.1. I have updated the system to Python 3.7.1 and have this is causing PythonEngine.Initialize() to crash the application without throwing an exception.
One internet suggestion was to set the Python env in VS, however this causes VS2017 to close when opening Python/environments. I switched to VS2019 and encountered the same issue with the stripped down code here:
using System.Windows.Forms;
using Python.Runtime;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
PythonEngine.Initialize();
}
catch (Exception e)
{
string ex = e.ToString();
}
}
}
}
Python.Net was installed successfully using:
pip install pythonnet
UPDATE Dec 2022
There are 2 optional environment strings you can use to locate the python dll.
PYTHONNET_PYDLL explicitly set the dll name
PYTHONNET_PYVER explicitly set just the version string part of the dll name
Compiling with WINDOWS, OSX or LINUX defined is not required anymore
Here's my PythonNet init function.
Note that running "pip install pythonnet" only installs the ability to load & use CLR types & assemblies from Python. To embed PythonNet in a C# app, you actually don't need to install pythonnet on the Python side.
This function uses some globals set at startup.
Program.PythonHome -- points to the Python root folder I'm using
Program.ScriptsDir -- my own app python scripts dir
Program.ApplicationName -- just my own app name
I also call PythonEngine.BeginAllowThreads(); as I'm calling from multiple threads.
public static void InitPython(Microsoft.Extensions.Logging.ILogger logger)
{
string py_home = Program.PythonHome;
string py_path = $"{py_home};";
// will be different on linux/mac
string[] py_paths = {"DLLs", "lib", "lib/site-packages", "lib/site-packages/win32"
, "lib/site-packages/win32/lib", "lib/site-packages/Pythonwin" };
foreach (string p in py_paths)
{
py_path += $"{py_home}/{p};";
}
try
{
PythonEngine.PythonPath = $"{Program.ScriptsDir};{py_path}";
PythonEngine.PythonHome = Program.PythonHome;
PythonEngine.ProgramName = Program.ApplicationName;
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
logger.LogInformation("Python Version: {v}, {dll}", PythonEngine.Version.Trim(), Runtime.PythonDLL);
logger.LogInformation("Python Home: {home}", PythonEngine.PythonHome);
logger.LogInformation("Python Path: {path}", PythonEngine.PythonPath);
}
catch (System.TypeInitializationException e)
{
throw new Exception($"FATAL, Unable to load Python, dll={Runtime.PythonDLL}", e);
}
catch (Exception e)
{
throw new Exception($"Python initialization Exception, {e.Message}", e);
}
}

NUnit3-Console.exe on Win Server 2012 has no TestFixtures

I have been running NUnit3-Console on Win 2012 for almost two years. I recently updated my tests to .Net 4.7.2 and updated the NUnit and Selenium to the latest versions. I have installed NUnit3-Console v3.8 on the server and .Net 4.7.2.
All of the tests that used to run fine now fail with the message "Has no TestFixtures.
I wrote a simple test to isolate the issue and it does the same thing.
My Base class
enter code here
using NUnit.Framework;
using Utilities;
namespace CommonCode2.TestBases
{
public class NoSeleniumBase
{
public Parameters parms = new Parameters();
[OneTimeSetUp]
public void InitializePageTests()
{
parms.GetParameters();
}
[OneTimeTearDown]
public void CleanupPageTests()
{
}
}
}
My SimpleTest
enter code here
using CommonCode2.TestBases;
using NUnit.Framework;
using System;
namespace SimpleTest
{
[TestFixture]
public class TestClass : NoSeleniumBase
{
[Test]
public void Atest()
{
Console.WriteLine("This is a simple test");
}
}
}
The NUnit files are installed in C:\NUnit and the test is invoked using.
C:\Nunit\NUnit3-Console.exe --where "name =~ 'Atest'"
"C:\QA_Libraries3\SimpleTest.dll"
The TestResult file contains this tag
<property name="_SKIPREASON" value="Has no TestFixtures" />
and a message block
<![CDATA[Has no TestFixtures]]></message>
I am hoping that someone has encountered this issue and can point me in the right direction.
Thanks to Charlie Poole and Rob Prouse for their responsive and helpful support. The issue was not with NUnit3-Console but with the tests library directory access. Deleting and recreating the directory resolved the issue.

What does compilationOptions.emitEntryPoint mean?

Just installed the rc1 tools and created a new web project to see what has changed in the template.
I noticed that project.json now contains:
"compilationOptions": {
"emitEntryPoint": true
}
But it's unclear what this does.
Does anyone have an idea?
As mentioned below: It looks like it is a flag to the compiler to indicate that the project is a console application vs. a library (namely: a console application must contain public static void Main())
You can see from the source here.
In the new RC1 default web application template, you'll notice at the bottom of Startup.cs there is a new expression bodied method that acts as the entry point:
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
If you remove this method then perform a build (dnu build) you will get an error:
error CS5001: Program does not contain a static 'Main' method suitable for an entry point
However, if you change the emitEntryPoint flag to false and attempt to build again, it will succeed. This is because it is creating a library instead of a console app.
I see this in the source;
var outputKind = compilerOptions.EmitEntryPoint.GetValueOrDefault() ?
OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary;
Looks like it tells the compiler whether to create a Console Application or a Library.
Additionaly, if you create a new Class Library (Package) and Console Application (Package) in VS2015 you'll see that project.json for the Console Application includes the following, while the Class Library does not;
"compilationOptions": {
"emitEntryPoint": true
}

MonoDevelop debugging error

I've recently changed to Ubuntu 11.10 (from Windows Vista).I use mono (2.8.5) as my IDE (C# VS.net before) to program.
As a quick test I want to make a console program with the following code:
using System;
namespace DeleteMe1
{
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
Console.ReadKey ();
}
}
}
If I run the program I see a screen appear and disappear (very quickly). When I debug I get the following error:
Could not open port for debugger. Another process may be using the port.
Is someone familiar with these messages? I've already tried the following:
https://stackoverflow.com/questions/8...using-the-port
But the property key (Property key="MonoTouch.Debugger.Port" value="10000") is not available.
Whats wrong?
Thanks in advance and with best regards.