Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

My Project is on C#/WPF Application, and I am new to this technology, I am facing issues, with selecting a specific *.dll, from host of dll's,

Basically, in Xaml(we have 3 dll's been build in bin folder) and mapped to the three buttons in the xaml, I need to wire the functionality of specific dll(assume b.dll) to some new button.,

here are the code snippets.<
C#
WorkCompletedCallBack callbackServices;
        WORKCOMPLETEDUI m_call;

        public List<imyservice> LoadServices(IMYServiceFinder srvFinder, WORKCOMPLETEDUI callback)
        {
            List<imyservice> srvRefss = new List<imyservice>();
            List<string> srvNames = srvFinder.GetServiceDllNames();
            foreach( string srvName in srvNames)
            {
                // Load the Assembly
                Assembly asm = null;
                try
                {
                    TraceMessage.Info("Load service : " + srvName);
                    asm = Assembly.LoadFile(srvName);                }
                // TODO: Catch appropriate exception
                catch(Exception ex)
                {
                    TraceMessage.Error("Exception during load file " + ex.ToString());                   
                    continue;
                }

                // Create the ServiceCreat instance which all the service module must implement
              ServiceEng.IMyServiceCreator mysc = null;
                try
                {
                    mysc = asm.CreateInstance("Services.ServiceCreated") as HBServiceEngine.IMYServiceCreator;
                    if (mysc == null)
                        continue;
                }
                catch (Exception ex)
                {
                    TraceMessage.Error("Exception during CreateInstance for ServiceCreat " + ex.ToString());                   
                    continue;
                }

                // Get the services that are supported by the service module
                ServiceEngine.IMYService mys = mysc.CreateService();
                m_call = callback;
                callbackServices = new WorkCompletedCallBack(Refresh);
                mys.Init(callbackServices);

                srvRefss.Add(qbs);
            }
            return srvRefss;
        }


Assuming, I have 4 dll's viz., a.dll, b.dll, c.dll, I want to load a specific dll viz., b.dll from the dll list, instead of all the dll's.

Details: VS 2010 IDE, Windows 7 o/s

Any help in resolving the above would be very helpful.

Regards,
VishalK
Posted
Updated 6-Aug-13 21:20pm
v2

 
Share this answer
 
Comments
Joezer BH 7-Aug-13 3:53am    
:)
Reading material for a couple of weeks
Sergey Alexandrovich Kryukov 7-Aug-13 9:34am    
Well, sorry to say, a lot of material is repeated...
—SA
Assembly.LoadFile(AsmFilePath) Loads the contents of an assembly file on the specified path. It does not load all the files of a folder.

So actually you don't have any problem - you decide which files to upload, meaning that each call to the LoadFile will load that specific file only.


* I see in your code that the variable you have as input is called SrvName which is not a very good name for a file, perhaps that is the source of your confusion?


Cheers,
Edo
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Aug-13 3:47am    
You are right, not this is not quite as simple. You load the assembly, then what?
This is really the problem of plug-in architecture and binding with plug-ins.
A pretty big topic I used to cover in many past answer. Please see my answer.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900