# [C#] Removing Application.Run = Errors

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

## 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    {        /// &lt;summary&gt;        /// The main entry point for the application.        /// &lt;/summary&gt;        [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 on other sites
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

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 12
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632152
• Total Posts
3004466

×