• Advertisement
Sign in to follow this  

[C#] Removing Application.Run = Errors

This topic is 2781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey!

I have some .NET-Assemblies which are not at the place of the .exe. Therefore i have set the additional path using:

AppDomain.CurrentDomain.AppendPrivatePath("Modules");



This worked good so far, but now i removed Application.Run because i have my own messageloop from SlimDX. This yields some errors:
While before the assemblies in the folder Modules were found correctly now they arent, they need to be at the place of the .exe. Thats why i suppose that Application.Run is doing some "magic" to set up the AppDomain correctly but i dont know what to do! My code so far:

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AppendPrivatePath("Modules");
Application.EnableVisualstyles();
Application.SetCompatibleTextRenderingDefault(false);
Video._3DManager mgr = new Video._3DManager(typeof(Form1));
mgr.BeginRender();
}
}



The problem: It says that the assembly Video could not be found. If i use Application.Run(new Form1()) and call the code with Video there all is good (except that at BeginRender i get an exception that already a messageloop is set up, but thats clear). If i copy the Video.dll to the .exe the above code works perfectly, but i want to have it at Modules.

Would be nice if someone could help me!

Greetings
Plerion

Share this post


Link to post
Share on other sites
Advertisement
Problem solved! The assemblies get loaded at the beginning of the function they are first used! So this helped:

static class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Startup()
{
Video._3DManager mgr = new Video._3DManager(typeof(Form1));
mgr.BeginRender();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AppendPrivatePath("Modules");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Startup();
}
}



NoInlining was neccessary as the compiler inlined Startup and therefore tried to load Video.dll again at the beginning of Main!

Greetings
Plerion

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement