.NET Compiler and OGRE [Solved]

Kwang1imsa

23-03-2011 16:32:38

I'm creating an application that uses the .NET compiler to compiler an application that uses MOGRE.
The code itself compiles and runs fine in Visual Studio, but for some reason, the application breaks if it's compiled programmatically. This is the line that seems to be doing it, even though it is not throwing any exception:
mRoot = new Root();

Here is how I compile it:
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("/reference/sfmlnet-window.dll");
cp.ReferencedAssemblies.Add("/reference/sfmlnet-graphics.dll");
cp.ReferencedAssemblies.Add("/reference/sfmlnet-audio.dll");
cp.ReferencedAssemblies.Add("/reference/Tao.Platform.Windows.dll");
cp.ReferencedAssemblies.Add("/reference/Tao.OpenGl.Glu.dll");
cp.ReferencedAssemblies.Add("/reference/Tao.OpenGl.ExtensionLoader.dll");
cp.ReferencedAssemblies.Add("/reference/Tao.OpenGl.dll");
cp.ReferencedAssemblies.Add("/reference/System.Data.dll");
cp.ReferencedAssemblies.Add("/reference/System.Core.dll");
cp.ReferencedAssemblies.Add("/reference/System.Data.Linq.dll");
cp.ReferencedAssemblies.Add("/reference/Mogre.dll");
//cp.ReferencedAssemblies.Add("/reference/MOIS.dll");
cp.ReferencedAssemblies.AddRange(MainGui.root.referenceList.ToArray());

//Debug
cp.ReferencedAssemblies.Add("/reference/System.Windows.Forms.dll");

cp.GenerateExecutable = true;
cp.OutputAssembly = exeName;
cp.GenerateInMemory = false;
cp.TreatWarningsAsErrors = false;
cp.CompilerOptions = "/platform:x86 /appconfig:App.config";

CompilerResults cr = provider.CompileAssemblyFromFile(cp,sourceName);


and the code I compile:
using System;
using System.Windows.Forms;
using SFML;
using SFML.Graphics;
using SFML.Window;
using Tao.OpenGl;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Mogre;
//using MOIS;

namespace gravitygame
{
class Game
{
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern bool FreeConsole();

public static Root mRoot;
public Game()
{
mRoot = new Root();
}
static void Main()
{
FreeConsole();
System.Windows.Forms.MessageBox.Show("Start.");
new Game();
System.Windows.Forms.MessageBox.Show("End.");
}
}
}


And to run it:
Process p = new Process();
p.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\bin\build\";
p.StartInfo.FileName = Directory.GetCurrentDirectory() + @"\bin\build\" + "App.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.ErrorDataReceived+=new DataReceivedEventHandler(p_ErrorDataReceived);


I can see "Start." flash and that's about it. However, when I take the same code and compile it in VS2010, it works fine.

Please help.

EDIT:

Actually, when I build it through VS2010 it doesn't work. However, when I run it through Debug mode, it does. Odd?

Also:

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>

ed.

smiley80

24-03-2011 09:53:02

You have to copy "app.config" (as exeName + ."config") to the output folder, the compiler won't do that for you.
Also you have to make sure that all references + their native dependencies are in the search path.

Btw. GAC assemblies can be referenced like this:
cp.ReferencedAssemblies.Add("System.Data.dll");
cp.ReferencedAssemblies.Add("System.Core.dll");
cp.ReferencedAssemblies.Add("System.Data.Linq.dll");
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");

Kwang1imsa

24-03-2011 14:09:32

You have to copy "app.config" (as exeName + ."config") to the output folder, the compiler won't do that for you.
Also you have to make sure that all references + their native dependencies are in the search path.

Btw. GAC assemblies can be referenced like this:
cp.ReferencedAssemblies.Add("System.Data.dll");
cp.ReferencedAssemblies.Add("System.Core.dll");
cp.ReferencedAssemblies.Add("System.Data.Linq.dll");
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");

If I use "/appconfig:App.config", doesn't that set the config file to "App.config"?

My output will be called "Game.exe". Included "App.config", "Game.config", and "Game.exe.config" in the same directory and it still crashes. It definitely does not have anything to do with dependencies and references. All of the dlls and dependencies are in the same directory as the application.

Any ideas?

smiley80

24-03-2011 16:33:53

If you remove 'FreeConsole();' and run the compiled program from the command line, do you get any output?


If I use "/appconfig:App.config", doesn't that set the config file to "App.config"?

The compiler only checks if there are compile-time options in app.config, it doesn't copy it over.
If you compile with VisualStudio, MSBuild will copy and rename app.config.

Kwang1imsa

24-03-2011 20:03:58

If you remove 'FreeConsole();' and run the compiled program from the command line, do you get any output?


If I use "/appconfig:App.config", doesn't that set the config file to "App.config"?

The compiler only checks if there are compile-time options in app.config, it doesn't copy it over.
If you compile with VisualStudio, MSBuild will copy and rename app.config.


This is my new code:
using System;
using System.Windows.Forms;
using SFML;
using SFML.Graphics;
using SFML.Window;
using Tao.OpenGl;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Mogre;
//using MOIS;

namespace gravitygame
{
class Game
{
public static Root mRoot=null;
static void Main()
{
try
{
System.Windows.Forms.MessageBox.Show("Start.");
//mRoot = new Root();
new Root();
System.Windows.Forms.MessageBox.Show("End.");
}
catch (SEHException e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
}


and no.

But still:
My output will be called "Game.exe". Included "App.config", "Game.config", and "Game.exe.config" in the same directory and it still crashes.


do I have to change the command to \appconfig:Game.exe.config?

Meharin

27-03-2011 07:39:48

When it crashes, do you get any error message at all, or does the process just disappear?
Is there anything written to the Ogre.log file?

Kwang1imsa

30-03-2011 21:08:23

Nothing in Ogre.log, but it is now solved.

Fixed by setting platform to x86, dubug mode on, allowing unsafe code, and disabling optimizations.

cp.CompilerOptions = "/platform:x86 /appconfig:App.config /debug:pdbonly /filealign:512 /target:winexe /optimize- /unsafe";

CodeKrash

09-04-2011 05:23:30

nice to see you got it solved. You will remove the optimize switch eventually right? I ask because I'm afraid that I might run into probs when I do that. Is the no optimization switch required to not crash?