{"id":6658,"date":"2014-04-20T21:48:52","date_gmt":"2014-04-20T21:48:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/20\/activator-createinstancefrom-and-referenced-assemblies-collection-of-common-programming-errors\/"},"modified":"2014-04-20T21:48:52","modified_gmt":"2014-04-20T21:48:52","slug":"activator-createinstancefrom-and-referenced-assemblies-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/20\/activator-createinstancefrom-and-referenced-assemblies-collection-of-common-programming-errors\/","title":{"rendered":"Activator.CreateInstanceFrom and referenced assemblies-Collection of common programming errors"},"content":{"rendered":"<p>After reading &#8220;Discover Techniques for Safely Hosting Untrusted Add-Ins with the .NET Framework 2.0&#8221; by Shawn Farkas in November 2005 MSDN issue (<\/p>\n<p>) I wrote a simple program to test it. The directory structure is (directories are in bold):<\/p>\n<p><strong>HostApp<\/strong>\u00a0 HostApp.exe\u00a0 Interfaces.dll\u00a0 AddinMgr.dll<\/p>\n<p>\u00a0\u00a0<strong>Addins<\/strong><\/p>\n<p>\n\u00a0 \u00a0\u00a0<strong>Test<\/strong><br \/>\n\u00a0\u00a0\u00a0 \u00a0 TestAddin.dll<\/p>\n<p>Interfaces.dll assembly has two interfaces: IHost and IAddin. AddinMgr.dll contains one class AddinManager which implements IHost. TestAddin.dll contains one class Test which implements IAddin.<\/p>\n<p>I create a new application domain with ApplicationBase pointing to Addins\\Test and then use Activator.CreateInstanceFrom to create an instance of AddinManager class in a new domain. Then AddinManager calls Activator.CreateInstance to create an instance of Test class. This is where the problem is: Activator.CreateInstance throws FileNotFoundException (could not load file or assembly &#8216;Interfaces&#8217;). But AppDomain.GetAssemblies() shows that Interfaces.dll was loaded in the new domain. If I copy Interfaces.dll in the Addins\\Test directory then everything works.<\/p>\n<p>So, my question is: how does CreateInstanceFrom(AppDomain appDomain, string assembly, string type) really works? It looks like assemblies loaded with CreateInstanceFrom are being treated differently by the runtime.<\/p>\n<p>Alex<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After reading &#8220;Discover Techniques for Safely Hosting Untrusted Add-Ins with the .NET Framework 2.0&#8221; by Shawn Farkas in November 2005 MSDN issue ( ) I wrote a simple program to test it. The directory structure is (directories are in bold): HostApp\u00a0 HostApp.exe\u00a0 Interfaces.dll\u00a0 AddinMgr.dll \u00a0\u00a0Addins \u00a0 \u00a0\u00a0Test \u00a0\u00a0\u00a0 \u00a0 TestAddin.dll Interfaces.dll assembly has two interfaces: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6658","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6658"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6658\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}