<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx</link><description>I was working on a home project for creating a motion-detector that works using a webcam. Instead of using a baby-monitor I am planning to run this on an old computer. I'll point the web-cam to my daugthers' crib and the program would monitor both sound</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#8970732</link><pubDate>Wed, 01 Oct 2008 00:24:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8970732</guid><dc:creator>Amorphic </dc:creator><description>&lt;p&gt;Just one problem!!!&lt;/p&gt;
&lt;p&gt;In case when the plugin assembly is dependent upon other libraries, which host app has no idea, how can you make sure that particular plugin is instantiated other than moving dependency dlls to either host prog path or GAC ????&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8970732" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#8554726</link><pubDate>Tue, 27 May 2008 14:49:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8554726</guid><dc:creator>Itamar</dc:creator><description>&lt;p&gt; var plugins = from string file in Directory.GetFiles(pluginDir, &amp;quot;*.dll&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from type in Assembly.LoadFile(file).GetTypes()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where type.IsClass &amp;amp;&amp;amp; type.IsPublic&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from intfc in type.GetInterfaces()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where intfc.Equals(typeof(IPlugin))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select (IPlugin)Activator.CreateInstance(type);&lt;/p&gt;
&lt;p&gt;Same thing but using linq.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8554726" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#8437991</link><pubDate>Tue, 29 Apr 2008 18:26:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8437991</guid><dc:creator>Sunny</dc:creator><description>&lt;p&gt;Thanks A ton man. U ROCK!!!!!. Although I was not making this kind of baby spy but i definately uprooted thousands of my hairs to make this Activator.CreateInstance work. Tried many overloads and changing dll from private to public and wasting several hours of my quality time untill i read this post. Its awesome.. thanks a lot.&lt;/p&gt;
&lt;p&gt;KR&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8437991" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#892215</link><pubDate>Sun, 29 Oct 2006 04:49:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:892215</guid><dc:creator>Arun</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Thanks for the code. I found out the defect. check out - &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.yoda.arachsys.com/csharp/plugin.html"&gt;http://www.yoda.arachsys.com/csharp/plugin.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The problem is that the IPlugin is loaded in the memory twice so that they are never evaluated as the same.&lt;/p&gt;
&lt;p&gt;The only possible solution for us is to create a class library of the Interface and add a reference to that in both the application and the class library(Plugin).&lt;/p&gt;
&lt;p&gt;It Works Great!!! Thanks for the code. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=892215" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#889679</link><pubDate>Sat, 28 Oct 2006 17:37:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:889679</guid><dc:creator>Arun</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The code is great. I am just trying out some project for my self. I have seen a lot of plugin based application so decided to build one.&lt;/p&gt;
&lt;p&gt;I have created similar code as yours but when the control comes to if condtion&lt;/p&gt;
&lt;p&gt;if((list&amp;lt;Type&amp;gt;)interface).contains(typeof(T))) &lt;/p&gt;
&lt;p&gt;It is not detecting the types as same. I don't know why. My spceifications are&lt;/p&gt;
&lt;p&gt;I have a public interface(IPlugin) under the same namespace(tstapp) in both the class library and the application. &lt;/p&gt;
&lt;p&gt;In the class library i have an class Class1 : IPlugin in the same namespace(tstapp)&lt;/p&gt;
&lt;p&gt;In application i call the getplugins and call one method in the plugin as specified.&lt;/p&gt;
&lt;p&gt;But the plugin never gets instantinated because of the reason specified above&lt;/p&gt;
&lt;p&gt;Can you find any defect !!!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=889679" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#741541</link><pubDate>Tue, 05 Sep 2006 22:45:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:741541</guid><dc:creator>Gangesh </dc:creator><description>Abhinaba, &amp;nbsp;&lt;br&gt;&lt;br&gt;I copied the Interface(base class) into both the dlls and the calling application (web app) thinking it could be something to do with the path stuff as I had the interface in a sepate dll.&lt;br&gt;&lt;br&gt;Abhinaba, Sorry to have bombarded with these questions. I will figure it out, I thought that it may be something else in code that needed to be done with Activator.CreateInstance(path/assemblyname, type) . Thanks!!!&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=741541" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#741526</link><pubDate>Tue, 05 Sep 2006 22:33:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:741526</guid><dc:creator>Gangesh </dc:creator><description>May be some permission issue since I am running &amp;quot;Activator.CreateInstance&amp;quot; from the web server ?&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=741526" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#741423</link><pubDate>Tue, 05 Sep 2006 21:10:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:741423</guid><dc:creator>Abhinaba Basu [MSFT]</dc:creator><description>Gangesh, I don't think I can help you with debugging this with just this much info. Could be that all the dependent assemblies are not present in the assembly look up paths. But it could be any other think as well....&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=741423" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#741180</link><pubDate>Tue, 05 Sep 2006 18:12:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:741180</guid><dc:creator>Gangesh</dc:creator><description>Abhinaba, Thanks alot for that code piece and idea (setting aliases). That’s useful. However actually I have to have only one assembly loaded up at anytime (due to memory constrains on the server).&lt;br&gt;&lt;br&gt;I have tried this at design time (compilation time) by swapping between the dll references, and could have two different Applications. But when needed to change to the other one have to recompile with the reference changed to the other dll. Involves going into the studio again. So thought of doing this at run time and refreshing the server to get the other dll.&lt;br&gt;&lt;br&gt;&lt;br&gt;I tried Activator.CreateInstance(path/assemblyname, type) without doing an Assembly.LoadFile(file). But was getting a runtime error message saying &amp;quot;Could not load file or assembly 'path\assemblyname' or one of its dependencies. The given assembly name or codebase was invalid. &amp;quot;&lt;br&gt;&lt;br&gt;I don't know what I am missing!!!&lt;br&gt;&lt;br&gt;Thanks for your advice.&lt;br&gt;&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=741180" width="1" height="1"&gt;</description></item><item><title>re: C# 2.0: Loading plugins at run-time using late binding</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/11/14/492458.aspx#732847</link><pubDate>Thu, 31 Aug 2006 07:17:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:732847</guid><dc:creator>Abhinaba Basu [MSFT]</dc:creator><description>Gangesh, check out &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/abhinaba/archive/2005/11/30/498278.aspx"&gt;http://blogs.msdn.com/abhinaba/archive/2005/11/30/498278.aspx&lt;/a&gt;. Even though the title does not match your description but essentially it does what you are looking for...&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=732847" width="1" height="1"&gt;</description></item></channel></rss>