What I want to do is to load in a dll dynamically (which I think I have achieved with this code below, a message box is showing the name of the class within the dll file). I then want to return the value of a variable which is defined by the string 'variableName'.

Any ideas?

private void Form1_Load(object sender, EventArgs e)
        {
            classLocation = @"E:\Projects\Dll\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll";
            variableName= "HelloWorld";
            CallClass1(classLocation,className);
        }

        static void CallClass1(string filename, string className)
        {            
            string fullFileName = new System.IO.FileInfo(filename).FullName;
            Assembly assembly = Assembly.LoadFile(filename);
           
foreach (Type type in assembly.GetTypes())
            {                
                //Get the property of variable 'variableName'
                MessageBox.Show(type.ToString());            
            }
           
        }

Thanks, Chris

How is that variable declared in the assembly? A static or const value? Is it a member of the class? You need to reflect in to the assembly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.