Combine DLL DLL into .EXE

I know there are many answers on this topic, but the example code that I found in this answer does not work for every .dll

I used this example.

public App() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly); } static Assembly ResolveAssembly(object sender, ResolveEventArgs args) { //We dont' care about System Assemblies and so on... if (!args.Name.ToLower().StartsWith("wpfcontrol")) return null; Assembly thisAssembly = Assembly.GetExecutingAssembly(); //Get the Name of the AssemblyFile var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll"; //Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name)); if (resources.Count() > 0) { var resourceName = resources.First(); using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName)) { if (stream == null) return null; var block = new byte[stream.Length]; stream.Read(block, 0, block.Length); return Assembly.Load(block); } } return null; } 

When I created a small program with only one window, it worked for her, but it did not work with my "big" dll. The settings in the "big" dll are the same as in my small program.

I can’t imagine why it sometimes works, and sometimes it doesn’t work. I also tested it with ICSharp.AvalonEdit.dll, unsuccessfully ..

can anyone imagine where the error is?

Change 1

When I run my program, he says that she did not find my dll.

Edit 2

I think I got the gist of my problem. If one of the DLLs I want to combine contains a link to a different dll, than I have become a FileNotFoundException . Does anyone know how to load / add also the internal required dll

Edit 3

When I use the code from Jiří Polášek, it works for some. My Fluent shows the error "Please attach a ResourceDictionary with styles, but I did it already in my App.xaml

 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 
+4
source share
1 answer

If your assembly reference requires other assemblies, you must include them in your application as well, either in the application folder or as a built-in resource. You can define referenced assemblies using Visual Studio, IL Spy, dotPeek or write your own tool using the Assembly.GetReferencedAssemblies method.

It is also possible that the AssemblyResolve event is fired before attaching a ResolveAssembly handler to it. The attach handler should be the first thing you do in your main method. In WPF, you need to create a new class using the new Main method, which sets it as a Startup object in the project settings.

 public class Program { [STAThreadAttribute] public static void Main() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly); WpfApplication1.App app = new WpfApplication1.App(); app.InitializeComponent(); app.Run(); } public static Assembly ResolveAssembly(object sender, ResolveEventArgs args) { // check condition on the top of your original implementation } } 

You should also check the protection status at the top of the ResolveAssembly so as not to exclude any reference assembly.

+1
source

Source: https://habr.com/ru/post/1494927/


All Articles