Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems after merging Fluent into main.exe

My Question is about a Fluent, which i merged with my program.exe in one merged.exe with this code:

    public class Program
    {
        [STAThreadAttribute]
        public static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            App.Main();
        }

        private static Assembly OnResolveAssembly(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;
        }
    }

My problem is that the Fluent Ribbon Control cant find any style, but i settled it with them code in my app.xaml

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

The second problem that i have with this solution is that i cant connect to my database(SQL Express) with my program when i start it without Visual Studio.

When i have the fluent in the same folder it just works, because then it don't load it from the embedded referenced fluent. And the Fluent can find the style too so.

Has anyone had similar experience with the merging of dll/fluent into the main.exe and can you show me how you solved it?

like image 404
Karl_Schuhmann Avatar asked Nov 12 '22 23:11

Karl_Schuhmann


1 Answers

Use Fody.Costura instead, that works for me (and I also use Fluent).

https://github.com/Fody/Costura

One of the important things is to let your app know that it must load the assembly. What I sometimes do to force the loading is this in your app startup:

Console.WriteLine(typeof(Fluent).Name);

like image 122
Geert van Horrik Avatar answered Nov 14 '22 21:11

Geert van Horrik