XmlSyntaxException: System error on Unity I use RSA Encryption - c#

I'm using this library https://github.com/TakuKobayashi/UnityCipher to RSA encrypt text to send to a server. Problem is, whenever I call the encrypt function, I get a XmlSyntaxException: System error with no explanation.
Here's my code:
string name=textfield.text;
string password=textfieldpass.text;
name=name.Remove(name.Length - 1, 1);
password=password.Remove(password.Length - 1, 1);
if(name=="") return;
GameObject.Find("sendtext").GetComponent<TMP_Text>().text="Sending...";
string plainText = (name+"&&."+password+"&&."+double.Parse(PlayerPrefs.GetString("followercounter")).ToString("N0").Replace(".", ""));
string encrypted = RSAEncryption.Encrypt(plainText,"-----BEGIN PUBLIC KEY-----
massive public key
-----END PUBLIC KEY-----" );
Debug.Log(encrypted);
StartCoroutine(GetRequest("https://www.peq42.com/highscore?"+encrypted));
Any idea what is the source of the error?
Full error:
XmlSyntaxException: System error.
System.Security.Util.Parser.GetRequiredSizes (System.Security.Util.TokenizerStream stream, System.Int32& index) (at <75633565436c42f0a6426b33f0132ade>:0)
System.Security.Util.Parser.ParseContents () (at <75633565436c42f0a6426b33f0132ade>:0)
System.Security.Util.Parser..ctor (System.Security.Util.Tokenizer t) (at <75633565436c42f0a6426b33f0132ade>:0)
System.Security.Util.Parser..ctor (System.String input) (at <75633565436c42f0a6426b33f0132ade>:0)
System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) (at <75633565436c42f0a6426b33f0132ade>:0)
UnityCipher.RSAEncryption.Encrypt (System.Byte[] src, System.String publicKey) (at Assets/Scripts/minorscripts/RSAEncryption.cs:30)
UnityCipher.RSAEncryption.Encrypt (System.String plain, System.String publicKey) (at Assets/Scripts/minorscripts/RSAEncryption.cs:21)
scoresubmit.sendScore () (at Assets/Scripts/minorscripts/scoresubmit.cs:28)

Related

Embedding Mono On MacOS not able to print floats

I have been embedding mono in a basic c++ application, and have run into an issue with printing any numbers but 0 from the c# script causes my c++ program to crash
I created the following c# code
using System;
using Arc.Entity;
namespace ExampleApp
{
public class PlayerMovement : Entity
{
public void Start()
{
float test = 1.0f;
Console.WriteLine("Hello Start Method: {0}", test);
}
public void Update()
{
translate.x += 1.0f;
Console.WriteLine("Translation: ({0}, {1})", translate.x, translate.y);
}
}
}
Which simply prints a float to the console, and I load the dll file thats created in Visual Studio For Mac with the following code.
C++
#include <iostream>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
int main(int argc, const char * argv[]) {
mono_set_dirs("/Library/Frameworks/Mono.framework/Versions/6.10.0/lib", "/Library/Frameworks/Mono.framework/Versions/6.10.0/etc");
MonoDomain* domain = mono_jit_init("Scripting_Engine");
MonoAssembly* assembly = mono_domain_assembly_open(domain, "/Desktop/ScriptingMacOSX/Build/Products/Debug/ExampleApp.dll");
MonoImage* image = mono_assembly_get_image(assembly);
if (!image)
{
std::cout << "Image Not Created" << std::endl;
} else {
std::cout << "Image Created" << std::endl;
}
MonoClass* scriptClass = mono_class_from_name(image, "ExampleApp", "PlayerMovement");
if(!scriptClass) {
std::cout << "Class Not Created" << std::endl;
} else {
std::cout << "Class Created" << std::endl;
}
MonoObject* scriptObject = mono_object_new(domain, scriptClass);
if(!scriptObject) {
std::cout << "Object Not Created" << std::endl;
} else {
std::cout << "Object Created" << std::endl;
}
mono_runtime_object_init(scriptObject);
void* iter = nullptr;
MonoMethod* method;
// Mono Methods
MonoMethod* startMethod = nullptr;
MonoMethod* updateMethod = nullptr;
std::string methodName = "Start";
while((method = mono_class_get_methods(scriptClass, &iter)))
{
if (strcmp(mono_method_get_name(method), "Start") == 0)
{
startMethod = method;
}
if (strcmp(mono_method_get_name(method), "Update") == 0)
{
updateMethod = method;
}
}
mono_runtime_invoke(startMethod, scriptObject, nullptr, nullptr);
while (true) {
mono_runtime_invoke(updateMethod, scriptObject, nullptr, nullptr);
}
return 0;
}
This Process works fine as long as the test variable in the c# script is a zero. As soon as it is non-zero, it produces the following error.
System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
--- End of inner exception stack trace ---
at System.Number.DoubleToNumber (System.Double value, System.Int32 precision, System.Number+NumberBuffer& number) [0x000b2] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.FormatSingle (System.Text.ValueStringBuilder& sb, System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info) [0x000d1] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.TryFormatSingle (System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info, System.Span`1[T] destination, System.Int32& charsWritten) [0x00015] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Single.TryFormat (System.Span`1[T] destination, System.Int32& charsWritten, System.ReadOnlySpan`1[T] format, System.IFormatProvider provider) [0x0000a] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00308] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00023] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.Format (System.IFormatProvider provider, System.String format, System.Object arg0) [0x00008] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0) [0x00007] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(string,object)
at System.Console.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at ExampleApp.PlayerMovement.Start () [0x00007] in <6b3c479fe6974a38b024c98ff963d353>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
--- End of inner exception stack trace ---
at System.Number.DoubleToNumber (System.Double value, System.Int32 precision, System.Number+NumberBuffer& number) [0x000b2] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.FormatSingle (System.Text.ValueStringBuilder& sb, System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info) [0x000d1] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Number.TryFormatSingle (System.Single value, System.ReadOnlySpan`1[T] format, System.Globalization.NumberFormatInfo info, System.Span`1[T] destination, System.Int32& charsWritten) [0x00015] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Single.TryFormat (System.Span`1[T] destination, System.Int32& charsWritten, System.ReadOnlySpan`1[T] format, System.IFormatProvider provider) [0x0000a] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00308] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00023] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.String.Format (System.IFormatProvider provider, System.String format, System.Object arg0) [0x00008] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0) [0x00007] in <55adae4546cd485ba70e2948332ebe8c>:0
at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(string,object)
at System.Console.WriteLine (System.String format, System.Object arg0) [0x00000] in <55adae4546cd485ba70e2948332ebe8c>:0
at ExampleApp.PlayerMovement.Start () [0x00007] in <6b3c479fe6974a38b024c98ff963d353>:0
I have been looking into it, and I am thinking it might be a linking error.
What I have linked
libmonosgen-2.0.a
As I said above, this works fine for a zero as the value of the variable, so I think the above library is the only thing I need linked
Any Help would be much appreciated

Accessing NetworkManager Connection Settings through dbus-sharp

I'm running Arch Linux with the following version of mcs:
>mcs --version
Mono C# compiler version 4.0.4.0
And the following version of dbus-sharp
>pacman -Ss dbus-sharp
extra/dbus-sharp 0.8.1-1 [installed] C# implementation of D-Bus
extra/dbus-sharp-glib 0.6.0-1 [installed] C# GLib implementation of D-Bus
This is my test program, based on the example code found here: https://gist.github.com/Ummon/4317268
I'm just trying to access the settings of the currently active connection, which should be returned as a 'Dict of {String, Dict of {String, Variant}}' as I've checked in the d-feet tool for the org.freedesktop.NetworkManager.Settings.Connection interface
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using DBus;
namespace NetworkManagerDictTest {
public class MyTest {
[Interface("org.freedesktop.NetworkManager.Settings.Connection")]
public interface IConnection {
IDictionary<string, IDictionary<string, object>> GetSettings();
}
readonly static string BUS_NAME = "org.freedesktop.NetworkManager";
public static void Main(string[] argv) {
org.freedesktop.DBus.Properties NetworkManagerProps = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, new ObjectPath("/org/freedesktop/NetworkManager"));
ObjectPath[] activeConnections = NetworkManagerProps.Get(BUS_NAME, "ActiveConnections") as ObjectPath[];
if (activeConnections.Length > 0) {
org.freedesktop.DBus.Properties ActiveConnectionProperties = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, activeConnections[0]);
ObjectPath ActiveConnectionPath = ActiveConnectionProperties.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection") as ObjectPath;
Console.WriteLine("Using connection path: " + ActiveConnectionPath);
IConnection connection = Bus.System.GetObject<IConnection>(BUS_NAME, ActiveConnectionPath);
Console.WriteLine("Connection Object ok");
IDictionary<string, IDictionary<string, object>> settings = connection.GetSettings();
Console.WriteLine(settings);
}
}
}
}
Compilation went without errors nor warnings:
mcs Test.cs -r:/usr/lib/mono/dbus-sharp-2.0/dbus-sharp.dll -r:/usr/lib/mono/dbus-sharp-glib-2.0/dbus-sharp-glib.dll
However my program crashes during execution with the following output:
>mono Test.exe
Using connection path: /org/freedesktop/NetworkManager/Settings/0
Connection Object ok
Unhandled Exception:
DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
What can I do to work around this problem? Am I making a mistake when working with the DBus? It seems that all the method calls up to GetSettings went without issues. I've also encountered a similar problem while trying to fix a bug in another project where dbus-sharp would throw an exception when calling GetSettings. Could this be an issue of dbus-sharp instead?
Taking a look at the source code it seems that dbus-sharp infers the return type directly from the signature of the declared method. Unfortunately it doesn't check if I'm using a parent class or interface of Dictionary, eventually it tries to read a DBus struct because of a fallback case which causes the exception as DBus structs are 8 byte padded while dicts use 4 bytes
Replacing all the IDictionary types with Dictionary worked fine and solved my problem.

Unhandled exception in c#, Destination array is not long enough to copy all the items in the collection

I am c# beginner and trying to read a binary file to calculate the frequency of the symbols inside the binary file. (Frequency is the number of time the symbols repeats).
In my first step I took I kept the data type of "symbol" read as "int" and code worked fine.
But now I wanted to make this symbol of generic type (I mean <T> type).
The code compiles with out any error in ubantu terminal.
But when I execute using "mono filename.exe BinaryFile.bin" This binary file is read at sole argument. Please see at last that how i got this Binary file toto.bin.
The error is :
hp#ubuntu:~/Desktop/Internship_Xav/templatescplus$ mono test.exe toto.bin
Unhandled Exception: System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
at System.BitConverter.PutBytes (System.Byte* dst, System.Byte[] src, Int32 start_index, Int32 count) [0x00000] in <filename unknown>:0
at System.BitConverter.ToInt64 (System.Byte[] value, Int32 startIndex) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.Huffman`1[System.Int64]..ctor (System.String[] args, System.Func`3 converter) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.MyClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
at System.BitConverter.PutBytes (System.Byte* dst, System.Byte[] src, Int32 start_index, Int32 count) [0x00000] in <filename unknown>:0
at System.BitConverter.ToInt64 (System.Byte[] value, Int32 startIndex) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.Huffman`1[System.Int64]..ctor (System.String[] args, System.Func`3 converter) [0x00000] in <filename unknown>:0
at shekhar_final_version_Csharp.MyClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
hp#ubuntu:~/Desktop/
My full code to do so is (narrowed code):
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Final
{
public class A < T > where T: struct, IComparable < T > , IEquatable < T >
{
public class Node
{
public T symbol;
public Node next;
public int freq;
} public Node Front;
public A(string[] args, Func < byte[], int, T > converter)
{
int size = Marshal.SizeOf(typeof (T));
Front = null;
using(var stream = new BinaryReader(System.IO.File.OpenRead(args[0])))
{
while (stream.BaseStream.Position < stream.BaseStream.Length)
{
byte[] bytes = stream.ReadBytes(size);
T processingValue = converter(bytes, 0);
Node pt, temp;
pt = Front;
while (pt != null)
{ Console.WriteLine("check1");
if (pt.symbol.Equals(processingValue))
{
pt.freq++;
break;
}
Console.WriteLine("Symbol : {0} frequency is : {1}", pt.symbol, pt.freq);
temp = pt;
pt = pt.next;
}
}
}
}
} //////////////////////////////////////////////////
public class MyClass
{
public static void Main(string[] args)
{
A < long > ObjSym = new A < long > (args, BitConverter.ToInt64);
}
}
}
I think the problem is created while creating object of type Huffman in public class MyClass. Could some one please help me how to get a rid of this problem by giving a solution (any piece of code would be highly appreciated)? Thanks.
If the size of the file is not a multitude of 8 bytes (64 bits), the last ReadBytes() will result in a byte[] smaller than 8 bytes, causing ToInt64() to fail.

.net To Mono -> System.Security.Cryptography.CryptographicException: Private/public key mismatch

Unhandled Exception: System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at BlaBlaFunc() [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at BlaBlaFunc() [0x00000] in <filename unknown>:0
Here is the Source Code:
string foo = "blabla";
System.Security.Cryptography.RSAParameters rsa_params = new System.Security.Cryptography.RSAParameters();
rsa_params.Modulus = Enumerable.Range(0, pubkey.Length)
.Where(x => x % 2 == 0)
.Select(x => System.Convert.ToByte(pubkey.Substring(x, 2), 16))
.ToArray();
rsa_params.Exponent = new byte[] { 1, 0, 1 };
System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
System.Security.Cryptography.RSAParameters d = rsa.ExportParameters(false);
rsa.ImportParameters(rsa_params);
byte[] sp = rsa.Encrypt(Encoding.UTF8.GetBytes(foo), false);
The .exe file which works fine in windows is compiled with vs2010. It was runned with mono under Ubuntu.
Run with this command:
mono --runtime=v4.0.30319 xxx.exe
How can i fix this?
Apparently the ExportParameters call generates a keypair, including private key, even though you specified false for the includePrivateParameters argument. (See the source code). The ImportParameters then overwrites only the public key (because you don't provide the private one) hence the mismatch. This may be a mono bug if it doesn't match documented behaviour. Check that and file a bug if applicable.
As a workaround, you can remove the ExportParameters or create a new instance that you import into.

How can I correctly use Mono.Unix.UnixPipes.CreatePipes?

I want to communicate with a subprocess using a pipe other than stdin, stdout and stderr. I'm trying to use Mono.Unix.UnixPipes.CreatePipes for this. However, I can't find any examples and my best guess of how to use it isn't working. It seems that the child process I create with Process.Start cannot write to the inherited file handle. I am wondering if perhaps it has not actually inherited the handle at all. Here's my (reduced) code:
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Threading;
using System.Collections.Generic;
using Mono.Unix;
class Program
{
static void Main(string[] args)
{
if (args.Length==0)
{
InvokeChildProcess(args);
}
else
{
RunAsChildProcess(args);
}
}
static int InvokeChildProcess(string[] aArgs)
{
var childToParentPipe = Mono.Unix.UnixPipes.CreatePipes();
var childToParentStream = childToParentPipe.Reading;
string childHandle = childToParentPipe.Writing.Handle.ToString();
var startInfo = new ProcessStartInfo(
System.Reflection.Assembly.GetExecutingAssembly().Location,
childHandle)
{
UseShellExecute = false,
};
Process childProcess = Process.Start(startInfo);
childToParentPipe.Writing.Close();
using (var reader = new StreamReader(childToParentStream))
{
Console.WriteLine("[PARENT] Waiting for child output...");
string output = reader.ReadToEnd();
Console.Write("[PARENT] Received output ({0} chars): ", output.Length);
Console.WriteLine(output);
Console.WriteLine("[PARENT] Waiting for child to exit...");
childProcess.WaitForExit();
Console.WriteLine("[PARENT] Saw child exit with code {0}.", childProcess.ExitCode);
return childProcess.ExitCode;
}
}
static void RunAsChildProcess(string[] args)
{
int handle=int.Parse(args[0]);
Console.WriteLine("[CHILD] Writing to file handle {0}.", handle);
var pipeToParent = new Mono.Unix.UnixStream(handle);
Thread.Sleep(2000);
using (var writer = new StreamWriter(pipeToParent))
{
writer.WriteLine("Message from child.");
writer.Flush();
Environment.Exit(123);
}
}
}
Here's the output when it runs:
weeble#weeble-vm-oneiric32:~/dev$ mono MinimalPipeTest.exe
[PARENT] Waiting for child output...
[PARENT] Received output (0 chars):
[PARENT] Waiting for child to exit...
[CHILD] Writing to file handle 4.
Unhandled Exception: System.ArgumentException: Can not write to stream
at System.IO.StreamWriter..ctor (System.IO.Stream stream, System.Text.Encoding encoding, Int32 bufferSize) [0x00000] in <filename unknown>:0
at System.IO.StreamWriter..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (System.IO.Stream)
at Program.RunAsChildProcess (System.String[] args) [0x00000] in <filename unknown>:0
at Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Can not write to stream
at System.IO.StreamWriter..ctor (System.IO.Stream stream, System.Text.Encoding encoding, Int32 bufferSize) [0x00000] in <filename unknown>:0
at System.IO.StreamWriter..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (System.IO.Stream)
at Program.RunAsChildProcess (System.String[] args) [0x00000] in <filename unknown>:0
at Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[PARENT] Saw child exit with code 1.
weeble#weeble-vm-oneiric32:~/dev$
This example was compiled and run with Mono 2.10 as distributed in Ubuntu Oneiric.
What am I doing wrong? How can I ensure that the child process will be able to write to the pipe?
EDIT - It looks like Process.Start does indeed close all file descriptors in the child process except for 0, 1 and 2. See here in CreateProcess:
https://github.com/mono/mono/blob/master/mono/io-layer/processes.c#L988
for (i = getdtablesize () - 1; i > 2; i--) {
close (i);
}
I guess that means I can't use UnixPipes and Process.Start. Is there another way?
As I understand it, you cannot use a pipe bi-directionally here. In other words, you cannot read and write with the same pipe. You need two.

Categories

Resources