<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for Lars Holm Jensen&#039;s Code Blog</title>
	<atom:link href="http://codeblog.larsholm.net/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeblog.larsholm.net</link>
	<description>Just another WordPress codeblog on C#, Silverlight and all things .NET</description>
	<lastBuildDate>Wed, 01 May 2013 00:11:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by Ian</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-629</link>
		<dc:creator>Ian</dc:creator>
		<pubDate>Wed, 01 May 2013 00:11:27 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-629</guid>
		<description><![CDATA[Vincent, thank you for tip about &quot;using statements&quot;.    I had everything else setup correctly, the 3rd party dll added to resources, and included as reference for compile time, and a separate class to instantiate an instance of the code above. But I still kept getting an error at runtime when 3rdpartylib.dll was not in exe dir.  The problem was that I had &quot;using 3rdpartylib&quot; in Program.cs and code references to 3rdpartylib in Main.   I created a separate class in its own file, moved the using and references there (removing all direct references to 3rdpartylib from Program.cs, and now it works fine.]]></description>
		<content:encoded><![CDATA[<p>Vincent, thank you for tip about &#8220;using statements&#8221;.    I had everything else setup correctly, the 3rd party dll added to resources, and included as reference for compile time, and a separate class to instantiate an instance of the code above. But I still kept getting an error at runtime when 3rdpartylib.dll was not in exe dir.  The problem was that I had &#8220;using 3rdpartylib&#8221; in Program.cs and code references to 3rdpartylib in Main.   I created a separate class in its own file, moved the using and references there (removing all direct references to 3rdpartylib from Program.cs, and now it works fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Avoid incorrect Silverlight XAP file caching by Chris</title>
		<link>http://codeblog.larsholm.net/2010/02/avoid-incorrect-caching-of-silverlight-xap-file/comment-page-1/#comment-616</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 12 Apr 2013 14:34:03 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=49#comment-616</guid>
		<description><![CDATA[I am still having issues in a LAMP environment.  Is is possible to post a more specific example of a javascript/html only solution for this?]]></description>
		<content:encoded><![CDATA[<p>I am still having issues in a LAMP environment.  Is is possible to post a more specific example of a javascript/html only solution for this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by Martin</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-615</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 22 Mar 2013 10:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-615</guid>
		<description><![CDATA[Awesmome, thanks!]]></description>
		<content:encoded><![CDATA[<p>Awesmome, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by John</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-603</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 22 Feb 2013 04:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-603</guid>
		<description><![CDATA[I wanted to share this with everyone as it took me a while to figure out and I&#039;m sure it will benefit someone else.

First off, the code above works perfectly as is without modification.  My problem was the way I was implementing it.

I&#039;m writing a console application and, even using this code, I kept getting a System.IO.FileNotFoundException error:

Could not load file or assembly &#039;MyEmbeddedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&#039; or one of its dependencies. The system cannot find the file specified.

Following Vincent&#039;s post above, I had created a &quot;loader&quot; class whose sole purpose was to instantiate another class and terminate.  This way, I wasn&#039;t &quot;using&quot; the embedded DLL before I tried to load it into memory.

The problem was, the code above (as is), creates a class constructor called App.  For a console application, at least, the class constructor does not get called upon launching the EXE.

To address this, you have two options:

1) You can modify the code above to be a static function in your &quot;loader&quot; class.
or
2) You can create a third class named something like EmbeddedAssemblyLoader.  In your Main() in the Loader class, you first instantiate the EmbeddedAssemblyLoader class, then you instantiate whatever class you have that needed MyEmbeddedAssembly.

Option 1:
namespace MyApp
{
    class Loader
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            
            MyNeedyClass mnc = new MyNeedyClass(args);

            return;
        }
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Debug.WriteLine(&quot;CurrentDomain_AssemblyResolve intercepted request for &quot; + args.Name);

            string dllName = args.Name.Contains(&#039;,&#039;) ? args.Name.Substring(0, args.Name.IndexOf(&#039;,&#039;)) : args.Name.Replace(&quot;.dll&quot;, &quot;&quot;);

            dllName = dllName.Replace(&quot;.&quot;, &quot;_&quot;);

            if (dllName.EndsWith(&quot;_resources&quot;)) return null;

            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(MyApp).Namespace + &quot;.Properties.Resources&quot;, System.Reflection.Assembly.GetExecutingAssembly());

            byte[] bytes = (byte[])rm.GetObject(dllName);

            Debug.WriteLine(&quot;CurrentDomain_AssemblyResolve is loading &quot; + dllName);

            return System.Reflection.Assembly.Load(bytes);
        }
    }
}


Option 2:
namespace MyApp
{
    class Loader
    {
        static void Main(string[] args)
        {
            EmbeddedAssemblyLoader eal = new EmbeddedAssemblyLoader();
            
            MyNeedyClass mnc = new MyNeedyClass(args);

            return;
        }
    }
    class EmbeddedAssemblyLoader
    {
        public EmbeddedAssemblyLoader()
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
        }

        System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Debug.WriteLine(&quot;EmbeddedAssemblyLoader intercepted request for &quot; + args.Name);

            string dllName = args.Name.Contains(&#039;,&#039;) ? args.Name.Substring(0, args.Name.IndexOf(&#039;,&#039;)) : args.Name.Replace(&quot;.dll&quot;, &quot;&quot;);

            dllName = dllName.Replace(&quot;.&quot;, &quot;_&quot;);

            if (dllName.EndsWith(&quot;_resources&quot;)) return null;

            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + &quot;.Properties.Resources&quot;, System.Reflection.Assembly.GetExecutingAssembly());

            byte[] bytes = (byte[])rm.GetObject(dllName);

            Debug.WriteLine(&quot;EmbeddedAssemblyLoader is loading &quot; + dllName);

            return System.Reflection.Assembly.Load(bytes);
        }
    }
}]]></description>
		<content:encoded><![CDATA[<p>I wanted to share this with everyone as it took me a while to figure out and I&#8217;m sure it will benefit someone else.</p>
<p>First off, the code above works perfectly as is without modification.  My problem was the way I was implementing it.</p>
<p>I&#8217;m writing a console application and, even using this code, I kept getting a System.IO.FileNotFoundException error:</p>
<p>Could not load file or assembly &#8216;MyEmbeddedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; or one of its dependencies. The system cannot find the file specified.</p>
<p>Following Vincent&#8217;s post above, I had created a &#8220;loader&#8221; class whose sole purpose was to instantiate another class and terminate.  This way, I wasn&#8217;t &#8220;using&#8221; the embedded DLL before I tried to load it into memory.</p>
<p>The problem was, the code above (as is), creates a class constructor called App.  For a console application, at least, the class constructor does not get called upon launching the EXE.</p>
<p>To address this, you have two options:</p>
<p>1) You can modify the code above to be a static function in your &#8220;loader&#8221; class.<br />
or<br />
2) You can create a third class named something like EmbeddedAssemblyLoader.  In your Main() in the Loader class, you first instantiate the EmbeddedAssemblyLoader class, then you instantiate whatever class you have that needed MyEmbeddedAssembly.</p>
<p>Option 1:<br />
namespace MyApp<br />
{<br />
    class Loader<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);</p>
<p>            MyNeedyClass mnc = new MyNeedyClass(args);</p>
<p>            return;<br />
        }<br />
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)<br />
        {<br />
            Debug.WriteLine(&#8220;CurrentDomain_AssemblyResolve intercepted request for &#8221; + args.Name);</p>
<p>            string dllName = args.Name.Contains(&#8216;,&#8217;) ? args.Name.Substring(0, args.Name.IndexOf(&#8216;,&#8217;)) : args.Name.Replace(&#8220;.dll&#8221;, &#8220;&#8221;);</p>
<p>            dllName = dllName.Replace(&#8220;.&#8221;, &#8220;_&#8221;);</p>
<p>            if (dllName.EndsWith(&#8220;_resources&#8221;)) return null;</p>
<p>            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(MyApp).Namespace + &#8220;.Properties.Resources&#8221;, System.Reflection.Assembly.GetExecutingAssembly());</p>
<p>            byte[] bytes = (byte[])rm.GetObject(dllName);</p>
<p>            Debug.WriteLine(&#8220;CurrentDomain_AssemblyResolve is loading &#8221; + dllName);</p>
<p>            return System.Reflection.Assembly.Load(bytes);<br />
        }<br />
    }<br />
}</p>
<p>Option 2:<br />
namespace MyApp<br />
{<br />
    class Loader<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            EmbeddedAssemblyLoader eal = new EmbeddedAssemblyLoader();</p>
<p>            MyNeedyClass mnc = new MyNeedyClass(args);</p>
<p>            return;<br />
        }<br />
    }<br />
    class EmbeddedAssemblyLoader<br />
    {<br />
        public EmbeddedAssemblyLoader()<br />
        {<br />
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);<br />
        }</p>
<p>        System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)<br />
        {<br />
            Debug.WriteLine(&#8220;EmbeddedAssemblyLoader intercepted request for &#8221; + args.Name);</p>
<p>            string dllName = args.Name.Contains(&#8216;,&#8217;) ? args.Name.Substring(0, args.Name.IndexOf(&#8216;,&#8217;)) : args.Name.Replace(&#8220;.dll&#8221;, &#8220;&#8221;);</p>
<p>            dllName = dllName.Replace(&#8220;.&#8221;, &#8220;_&#8221;);</p>
<p>            if (dllName.EndsWith(&#8220;_resources&#8221;)) return null;</p>
<p>            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + &#8220;.Properties.Resources&#8221;, System.Reflection.Assembly.GetExecutingAssembly());</p>
<p>            byte[] bytes = (byte[])rm.GetObject(dllName);</p>
<p>            Debug.WriteLine(&#8220;EmbeddedAssemblyLoader is loading &#8221; + dllName);</p>
<p>            return System.Reflection.Assembly.Load(bytes);<br />
        }<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by DamDam</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-581</link>
		<dc:creator>DamDam</dc:creator>
		<pubDate>Wed, 13 Feb 2013 13:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-581</guid>
		<description><![CDATA[Great! Thanks, it works well!]]></description>
		<content:encoded><![CDATA[<p>Great! Thanks, it works well!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by Nicolás</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-569</link>
		<dc:creator>Nicolás</dc:creator>
		<pubDate>Fri, 08 Feb 2013 15:42:33 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-569</guid>
		<description><![CDATA[Just wanted to say: Great Work!!! Thank you!]]></description>
		<content:encoded><![CDATA[<p>Just wanted to say: Great Work!!! Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on C# string to alphanumeric by larsholm</title>
		<link>http://codeblog.larsholm.net/2011/06/c-string-to-alphanumeric/comment-page-1/#comment-534</link>
		<dc:creator>larsholm</dc:creator>
		<pubDate>Fri, 25 Jan 2013 12:40:07 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=108#comment-534</guid>
		<description><![CDATA[I realise now that it might be bad practice to rely on the order in which Where returns items.]]></description>
		<content:encoded><![CDATA[<p>I realise now that it might be bad practice to rely on the order in which Where returns items.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by zass</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-501</link>
		<dc:creator>zass</dc:creator>
		<pubDate>Fri, 10 Aug 2012 17:49:30 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-501</guid>
		<description><![CDATA[Hi Lars,

Thanks for publishing this. I can&#039;t get this to work, I&#039;ve created a very simple solution to show what I&#039;m doing.

I have a DLL that has one function, called ReturnA(). All it does is return the character &#039;A&#039;. Its source code is:

namespace ClassLibrary1
{
    public class Class1
    {
        public static char ReturnA()
        {
            return &#039;A&#039;;
        }
    }
}


I then have a simple console application that just tries to call this function. As you posted, I added a reference to the DLL, and I also added it as a resource in resources/ClassLibrary1.dll. I selected &quot;Embedded Resource&quot; as a build action. The code for the console app is:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary1;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] command_line_args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            Console.WriteLine(&quot;Testing to write a line before embedded DLL function is called&quot;);
            Caller caller = new Caller();
            caller.WriteToLine();
        }

        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {

            string dllName = args.Name.Contains(&#039;,&#039;) ? args.Name.Substring(0, args.Name.IndexOf(&#039;,&#039;)) : args.Name.Replace(&quot;.dll&quot;, &quot;&quot;);
            dllName = dllName.Replace(&quot;.&quot;, &quot;_&quot;);
            if (dllName.EndsWith(&quot;_resources&quot;)) return null;
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Program).Namespace + &quot;.Properties.Resources&quot;, System.Reflection.Assembly.GetExecutingAssembly());
            byte[] bytes = (byte[])rm.GetObject(dllName);
            return System.Reflection.Assembly.Load(bytes);
        }
    }


    public class Caller
    {
        public void WriteToLine()
        {
            char foo = Class1.ReturnA();
            Console.WriteLine(foo);
            Console.ReadLine();
        }
    }
}


When I call this application from the command line, it doesn&#039;t work if the ClassLibrary1.dll file isn&#039;t in the same directory. As far as I can tell, I have followed your instructions completely. I even put the call to the DLL function in another class, just to make sure. 

I have the solution available at: http://bit.ly/P9N86L

Thank you for any help!]]></description>
		<content:encoded><![CDATA[<p>Hi Lars,</p>
<p>Thanks for publishing this. I can&#8217;t get this to work, I&#8217;ve created a very simple solution to show what I&#8217;m doing.</p>
<p>I have a DLL that has one function, called ReturnA(). All it does is return the character &#8216;A&#8217;. Its source code is:</p>
<p>namespace ClassLibrary1<br />
{<br />
    public class Class1<br />
    {<br />
        public static char ReturnA()<br />
        {<br />
            return &#8216;A&#8217;;<br />
        }<br />
    }<br />
}</p>
<p>I then have a simple console application that just tries to call this function. As you posted, I added a reference to the DLL, and I also added it as a resource in resources/ClassLibrary1.dll. I selected &#8220;Embedded Resource&#8221; as a build action. The code for the console app is:</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using ClassLibrary1;<br />
using System.Reflection;</p>
<p>namespace ConsoleApplication1<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] command_line_args)<br />
        {<br />
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);</p>
<p>            Console.WriteLine(&#8220;Testing to write a line before embedded DLL function is called&#8221;);<br />
            Caller caller = new Caller();<br />
            caller.WriteToLine();<br />
        }</p>
<p>        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)<br />
        {</p>
<p>            string dllName = args.Name.Contains(&#8216;,&#8217;) ? args.Name.Substring(0, args.Name.IndexOf(&#8216;,&#8217;)) : args.Name.Replace(&#8220;.dll&#8221;, &#8220;&#8221;);<br />
            dllName = dllName.Replace(&#8220;.&#8221;, &#8220;_&#8221;);<br />
            if (dllName.EndsWith(&#8220;_resources&#8221;)) return null;<br />
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Program).Namespace + &#8220;.Properties.Resources&#8221;, System.Reflection.Assembly.GetExecutingAssembly());<br />
            byte[] bytes = (byte[])rm.GetObject(dllName);<br />
            return System.Reflection.Assembly.Load(bytes);<br />
        }<br />
    }</p>
<p>    public class Caller<br />
    {<br />
        public void WriteToLine()<br />
        {<br />
            char foo = Class1.ReturnA();<br />
            Console.WriteLine(foo);<br />
            Console.ReadLine();<br />
        }<br />
    }<br />
}</p>
<p>When I call this application from the command line, it doesn&#8217;t work if the ClassLibrary1.dll file isn&#8217;t in the same directory. As far as I can tell, I have followed your instructions completely. I even put the call to the DLL function in another class, just to make sure. </p>
<p>I have the solution available at: <a href="http://bit.ly/P9N86L" rel="nofollow">http://bit.ly/P9N86L</a></p>
<p>Thank you for any help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by larsholm</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-493</link>
		<dc:creator>larsholm</dc:creator>
		<pubDate>Wed, 25 Jul 2012 07:00:31 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-493</guid>
		<description><![CDATA[My guess would be that either the assembly has an external manifest file which it can not find (which does not trigger AssemblyResolve) or that the assembly is not a .NET assembly.]]></description>
		<content:encoded><![CDATA[<p>My guess would be that either the assembly has an external manifest file which it can not find (which does not trigger AssemblyResolve) or that the assembly is not a .NET assembly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Embed managed dlls easily in a .NET assembly by Rao</title>
		<link>http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-492</link>
		<dc:creator>Rao</dc:creator>
		<pubDate>Tue, 24 Jul 2012 13:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://codeblog.larsholm.net/?p=76#comment-492</guid>
		<description><![CDATA[Hello,

When I used the solution above, I am getting the below error.

Could not load file or assembly &#039;ServiceAgent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#039; or one of its dependenciesAn expected resource in the assembly manifest was missing. (Exception from HRESULT: 0x80131532)

My scenario is I have a DLL_1 which is using several other dlls. I added all these dependent dlls as resources and updated properties to Embedded Resource.

I have a client application (.Exe), included DLL_1. I added following code in program.cs (.Exe)

[STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {

            string dllName = args.Name.Contains(&quot;,&quot;) ? args.Name.Substring(0, args.Name.IndexOf(&#039;,&#039;)) : args.Name.Replace(&quot;.dll&quot;, &quot;&quot;);

            dllName = dllName.Replace(&quot;.&quot;, &quot;_&quot;);

            if (dllName.EndsWith(&quot;_resources&quot;)) return null;

            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Program).Namespace + &quot;.Properties.Resources&quot;, System.Reflection.Assembly.GetExecutingAssembly());

            byte[] bytes = (byte[])rm.GetObject(dllName);

            return System.Reflection.Assembly.Load(bytes);

        }

Not sure why I am getting the error. I appreciate your help.

Thanks,
Rao.]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>When I used the solution above, I am getting the below error.</p>
<p>Could not load file or assembly &#8216;ServiceAgent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; or one of its dependenciesAn expected resource in the assembly manifest was missing. (Exception from HRESULT: 0&#215;80131532)</p>
<p>My scenario is I have a DLL_1 which is using several other dlls. I added all these dependent dlls as resources and updated properties to Embedded Resource.</p>
<p>I have a client application (.Exe), included DLL_1. I added following code in program.cs (.Exe)</p>
<p>[STAThread]<br />
        static void Main()<br />
        {<br />
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);</p>
<p>            Application.EnableVisualStyles();<br />
            Application.SetCompatibleTextRenderingDefault(false);<br />
            Application.Run(new Form1());<br />
        }</p>
<p>        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)<br />
        {</p>
<p>            string dllName = args.Name.Contains(&#8220;,&#8221;) ? args.Name.Substring(0, args.Name.IndexOf(&#8216;,&#8217;)) : args.Name.Replace(&#8220;.dll&#8221;, &#8220;&#8221;);</p>
<p>            dllName = dllName.Replace(&#8220;.&#8221;, &#8220;_&#8221;);</p>
<p>            if (dllName.EndsWith(&#8220;_resources&#8221;)) return null;</p>
<p>            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Program).Namespace + &#8220;.Properties.Resources&#8221;, System.Reflection.Assembly.GetExecutingAssembly());</p>
<p>            byte[] bytes = (byte[])rm.GetObject(dllName);</p>
<p>            return System.Reflection.Assembly.Load(bytes);</p>
<p>        }</p>
<p>Not sure why I am getting the error. I appreciate your help.</p>
<p>Thanks,<br />
Rao.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
