Using # C.net 3.5
I know about ILMerge and similar methods, but I would like to use Jeffrey Richter's suggestions .
After adding this code to the constructor, there are problems with the namespace.
Jeffrey Richter Code:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { String resourceName = "AssemblyLoadingAndReflection." + new AssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } };
I installed the two DLLs as an “Embedded Resource” and added them as a link, but when I create the program, the two dlls are still “Un-embbeded”, I deleted them as a link, but then when I built the program there are errors saying : "type or namespace could not be found ... are you missing a use directive or assembly reference?" I have two namespaces added as using ... directive, then I tried to remove two links and two using directives and still errors.
here is my code:
using System.Reflection; namespace WindowsFormsApplication2 { public partial class Ndice : Form { public Ndice() { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { String resourceName = "AssemblyLoadingAndReflection." + new AssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } }; InitializeComponent(); } } }
source share