Loading a dll file containing a winforms

Viewed 63

i have a solution cotaining two projects. A -> is a windowsforms project, B -> is a EXE project. I want to refrence A in B dynamically using the A.dll generated after build. but when i try to load A.dll in B and GetTypes(). I get this error :

    System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

I tried loading System.Windows.Forms and all the referenced assemblies before gettypes but i ran into another error :

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

It seems that there is something that i can't figure out and im just running in closed loops.

My code :

Assembly assembly = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\A.dll");
            
            var list = assembly.GetReferencedAssemblies().ToList();
            foreach (var asm in list) {
                AppDomain.CurrentDomain.Load(asm);
                    }
            Console.WriteLine(assembly.GetTypes());
0 Answers
Related