<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Additional .dll files as resource in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10641687#M23565</link>
    <description>&lt;P&gt;I'm developing a REVIT addin that needs a external .dll library.&lt;BR /&gt;In order to reduce the number of deployed files, I want to integrate that .dll library as a resource. However, I'm struggling with associating the event handler for the AssemblyResolve. The event dosen't fire up when a not found library is raised.&lt;/P&gt;&lt;P&gt;Where should I place the bellow AddHandler command? At OnStart event handler (that runs when REVIT loads the addin) or at the addin Execute (that runs when REVIT executes the command)?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveAssemblies&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any example on this?&lt;BR /&gt;Do you deploy additional dll libraries as a separate files, or do you integrate then in the main addin .dll as a resource?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 08:17:33 GMT</pubDate>
    <dc:creator>antonio_hipolito</dc:creator>
    <dc:date>2021-09-23T08:17:33Z</dc:date>
    <item>
      <title>Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10641687#M23565</link>
      <description>&lt;P&gt;I'm developing a REVIT addin that needs a external .dll library.&lt;BR /&gt;In order to reduce the number of deployed files, I want to integrate that .dll library as a resource. However, I'm struggling with associating the event handler for the AssemblyResolve. The event dosen't fire up when a not found library is raised.&lt;/P&gt;&lt;P&gt;Where should I place the bellow AddHandler command? At OnStart event handler (that runs when REVIT loads the addin) or at the addin Execute (that runs when REVIT executes the command)?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveAssemblies&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any example on this?&lt;BR /&gt;Do you deploy additional dll libraries as a separate files, or do you integrate then in the main addin .dll as a resource?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 08:17:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10641687#M23565</guid>
      <dc:creator>antonio_hipolito</dc:creator>
      <dc:date>2021-09-23T08:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10641998#M23566</link>
      <description>&lt;P&gt;I believe most people ship them as separate DLLs. I have never heard of anyone doing what you propose, although it sounds useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 10:51:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10641998#M23566</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-09-23T10:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10642270#M23567</link>
      <description>&lt;P&gt;I tried this to get out of some .dll hell issues I was having. It worked, but statically linking .dlls as an embedded resources like this can cause issues with other add-ins, I found (pyRevit in my case). If that doesn't happen for you, then great! There may still be some pros and cons of doing it this way vs. shipping separate though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add the usual event listener to your startup:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will need to add the .dlls you're referencing as an embedded resources (In VS, Add-&amp;gt;Existing Items, then under Properties, change Build Action to Embedded Resource). I put all of my .dlls in an Assemblies folder for tidyness. Then you can use the following code for your AssemblyResolve function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string assemblyName = args.RequestingAssembly.GetName().Name;
            if(assemblyName == "YourAssemblyName")
            {
                string resourceName = "YourAssemblyName.Assemblies." + new AssemblyName(args.Name).Name + ".dll";
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    if (stream != null)
                    {
                        byte[] assemblyData = new byte[stream.Length];
                        stream.Read(assemblyData, 0, assemblyData.Length);
                        return Assembly.Load(assemblyData); 
                    }
                }
            }
            return null;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this works for you. I got stuck trying to fix the issues it was causing with pyRevit and reverted to shipping the .dlls separately. I'd be curious to see if there is a way to workaround it. That's what I was trying to do with the lines that were checking the calling assembly name. Perhaps someone with more experience in how the CLR loads in assemblies could give some insight.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 12:39:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10642270#M23567</guid>
      <dc:creator>josh.roth.MEI</dc:creator>
      <dc:date>2021-09-23T12:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10646576#M23568</link>
      <description>&lt;P&gt;Try subscribe to AssemblyResolve event in the static constructor of your implementation of IExternalApplication&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 06:31:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10646576#M23568</guid>
      <dc:creator>Kennan.Chen</dc:creator>
      <dc:date>2021-09-25T06:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10653802#M23569</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6280712"&gt;@josh.roth.MEI&lt;/a&gt;and &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4439905"&gt;@antonio_hipolito&lt;/a&gt;&amp;nbsp;you could use &lt;A href="https://github.com/Fody/Costura" target="_blank" rel="noopener"&gt;Fody.Costura&lt;/A&gt; to embed the .dll references automatically, the &lt;A href="https://github.com/Fody/Costura/tree/develop/src/Costura.Template" target="_blank" rel="noopener"&gt;Costura.Template&lt;/A&gt; has the &lt;SPAN class="css-truncate css-truncate-target d-block width-fit"&gt;&lt;STRONG&gt;ILTemplate.cs&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;Common.cs&lt;/STRONG&gt; to handle all the load resources files, if the Assembly is already loaded the code does not force it to load again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/824630"&gt;@jeremy_tammik&lt;/a&gt;I use this technic on the &lt;A href="https://apps.autodesk.com/RVT/en/Detail/Index?id=9120027511121592515" target="_blank" rel="noopener"&gt;ConduitMaterial&lt;/A&gt; and others plugins.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adding... &lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class="pl-smi"&gt;ILTemplate&lt;/SPAN&gt;.&lt;SPAN class="pl-en"&gt;Attach&lt;/SPAN&gt;();&lt;/EM&gt;&lt;/STRONG&gt; on the IExternalApplication should do the trick.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See yaa&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 23:50:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10653802#M23569</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2021-09-28T23:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10654420#M23570</link>
      <description>&lt;P&gt;Thank all for you suggestions.&lt;/P&gt;&lt;P&gt;I'll try them out.&lt;/P&gt;&lt;P&gt;Regards!I&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 07:49:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10654420#M23570</guid>
      <dc:creator>antonio_hipolito</dc:creator>
      <dc:date>2021-09-29T07:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683296#M23571</link>
      <description>&lt;P&gt;I also wanted to chime in here with resources. Ehsan actually hopped on a call with me and showed me his process with submodules. Since then that's how I have been handling other libraries that I need to use in my project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While I started with an AssemblyResolver, loading in a newer version of the assembly will not resolve correctly when a previous version has already been loaded. This came about because of the CTC addins still used the MahApps version 2 (I believe). Then I come barreling in to the situation with&amp;nbsp; the new 3.x versions of MahApps because I wanted to use the new, fancy features. Revit will resolve everything up to the point where you wanted to use one of the 3.x features that the 2.x didn't have. Then my app would throw an Exception telling me that it couldn't find that 3.x feature because CTC had loaded the 2.x version first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, Ehsan told me about submodules in git (which I had to learn about) and re-building MahApps open-source code under a new .dll name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Opening the open-source project, changing the name, building the submodules, and then referencing the new submodules have been fantastic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is a snippet of my library with the re-built MahApps content. Also if you look in pyRevit's library, Ehsan does the same thing, or at least used to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kudos of course to Ehsan for showing me this and thanks to Jeremy for pointing me here from the blog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this helps someone in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 14:38:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683296#M23571</guid>
      <dc:creator>kraftwerk15</dc:creator>
      <dc:date>2021-10-12T14:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683367#M23572</link>
      <description>&lt;P&gt;Same issue with MahApps before and I also rebuilt the whole project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Life can be easier to compile&amp;nbsp;MahApps project with another&amp;nbsp;&lt;SPAN&gt;Public/Private key pair(.snk&amp;nbsp;&lt;/SPAN&gt;file), which will sign a unique strong name to the dll. Referencing a strong-named dll is supposed to be a common practise to "dll hell" issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/standard/assembly/strong-named" target="_blank"&gt;Strong-named assemblies | Microsoft Docs&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 15:10:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683367#M23572</guid>
      <dc:creator>Kennan.Chen</dc:creator>
      <dc:date>2021-10-12T15:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683753#M23573</link>
      <description>&lt;P&gt;Many thanks to everybody for all your helpful advice!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I summarised and edited it on the blog for posterity:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2021/10/dll-as-resource-and-multi-version-add-ins.html#5" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2021/10/dll-as-resource-and-multi-version-add-ins.html#5&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 17:57:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10683753#M23573</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-10-12T17:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10685051#M23574</link>
      <description>&lt;P&gt;Thanks again for all your thoughts!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 08:36:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/10685051#M23574</guid>
      <dc:creator>antonio_hipolito</dc:creator>
      <dc:date>2021-10-13T08:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12140630#M23575</link>
      <description>&lt;P&gt;Hello, maybe you will provide an example, I'm trying to do the same thing but I don't know where to start.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 08:49:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12140630#M23575</guid>
      <dc:creator>minet.axel</dc:creator>
      <dc:date>2023-08-01T08:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12144742#M23576</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some information.&lt;/P&gt;&lt;P&gt;If I modify the signature of the MahApps project and I recompile the project without modifying the name of the assembly. Does this work? Because in the project there are lots of references to the MahApps assembly name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thk&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 17:21:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12144742#M23576</guid>
      <dc:creator>minet.axel</dc:creator>
      <dc:date>2023-08-02T17:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Additional .dll files as resource</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12145633#M23577</link>
      <description>&lt;P&gt;Theoretically, you don't need to rename the dll name once your have sign a strong name to the dll and reference that dll directly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Weird thing is I went through my code written years ago and found that I actually did the renaming. I could not recall why I did that and whether it was necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;One thing to mention is that an add-in is a part of Revit and there could be other add-ins referencing MahApps without strong name. If your add-in uses a strong-named MahApps.dll, add-ins that loaded after your add-in will use your MahApps.dll, which could cause those add-ins to fail to load because of the incompatible version. Renaming your strong-named MahApps dll can prevent your add-in from "polluting" the common .NET runtime in Revit.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 04:44:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/additional-dll-files-as-resource/m-p/12145633#M23577</guid>
      <dc:creator>Kennan.Chen</dc:creator>
      <dc:date>2023-08-03T04:44:59Z</dc:date>
    </item>
  </channel>
</rss>

