<?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 Re: Autoloader fails with IExtensionApplication in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10303039#M16486</link>
    <description>&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;you can try this way:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public void Initialize()
{
    Autodesk.AutoCAD.ApplicationServices.Core.Application.Idle += OnIdle;
}

private void OnIdle(object sender, EventArgs e)
{
    try
    {
        Autodesk.AutoCAD.ApplicationServices.Core.Application.Idle -= OnIdle;
        BikubeRibbon();
    }
    catch (System.Exception ex)
    {
        var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage($"\nError: {ex.Message}");
    }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 15 Apr 2025 06:27:13 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2025-04-15T06:27:13Z</dc:date>
    <item>
      <title>Autoloader fails with IExtensionApplication</title>
      <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10302677#M16485</link>
      <description>&lt;P&gt;I am experiencing problems when i use Autoloader together with&amp;nbsp;IExtensionApplication.&lt;/P&gt;&lt;P&gt;If i load the dll with netload everything works fine, but if i load it with the Autoloader in a bundle it fails, and i cant fix it by using netload afterwords. If i remove the &amp;nbsp;IExtensionApplication spesific code, the Autoloader works fine again.&lt;/P&gt;&lt;P&gt;Does anyone know why this happens?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class AV_Ribbon : IExtensionApplication
    {
        private const string BIKUBE_TAB_ID = "AV_BIKUBE_TAB_ID";
        public void Initialize()
        {
            BikubeRibbon();
        }
        public void Terminate()
        {

        }
        [CommandMethod("BikubeRibbon")]
        public void BikubeRibbon()
        {
            Autodesk.Windows.RibbonControl ribCntrl =
                Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
            //can also be Autodesk.Windows.ComponentManager.Ribbon;     
            RibbonTab ribTab = new RibbonTab();
            ribTab.Title = "Bikube";
            ribTab.Id = BIKUBE_TAB_ID;
            ribCntrl.Tabs.Add(ribTab);

            LeggTilPublPanel(ribTab);
            //ribTab.IsActive = true; //Bytter til denne Tab-en ved innlasting
        }
        private void LeggTilPublPanel(RibbonTab ribTab)
        {
            RibbonPanelSource ribPanelSource = new RibbonPanelSource();
            ribPanelSource.Title = "Publisering";

            RibbonPanel ribPanel = new RibbonPanel();
            ribPanel.Source = ribPanelSource;
            ribTab.Panels.Add(ribPanel);

            RibbonButton ribButton = new RibbonButton();
            ribButton.Size = RibbonItemSize.Large;
            ribButton.Text = "Publiser";
            ribButton.Orientation = System.Windows.Controls.Orientation.Vertical;
            ribButton.LargeImage = GetBitmap(new Bitmap(Properties.Resources.BikubePublisering_ikon_40x40));
            ribButton.ShowText = true;
            ribButton.CommandParameter = "PubliserTilBikube "; //HUSK: mellomrom etter kommando
            ribButton.CommandHandler = new AdskCommandHandler();
            ribPanelSource.Items.Add(ribButton);
        }
        private BitmapImage GetBitmap(Bitmap image)
        {
            MemoryStream stream = new MemoryStream();
            image.Save(stream, ImageFormat.Png);
            BitmapImage bmp = new BitmapImage();
            bmp.BeginInit();
            bmp.StreamSource = stream;
            bmp.EndInit();
            return bmp;
        }
    }
    class AdskCommandHandler : System.Windows.Input.ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }
        public event EventHandler CanExecuteChanged;
        public void Execute(object parameter)
        {
            //is from Ribbon Button
            RibbonButton ribBtn = parameter as RibbonButton;
            if (ribBtn != null)
            {
                //execute the command 
                acApp.DocumentManager.MdiActiveDocument
                .SendStringToExecute(
                   (string)ribBtn.CommandParameter, true, false, true);
            }
        }
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 10 May 2021 13:36:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10302677#M16485</guid>
      <dc:creator>christian.hestnes</dc:creator>
      <dc:date>2021-05-10T13:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader fails with IExtensionApplication</title>
      <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10303039#M16486</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;you can try this way:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public void Initialize()
{
    Autodesk.AutoCAD.ApplicationServices.Core.Application.Idle += OnIdle;
}

private void OnIdle(object sender, EventArgs e)
{
    try
    {
        Autodesk.AutoCAD.ApplicationServices.Core.Application.Idle -= OnIdle;
        BikubeRibbon();
    }
    catch (System.Exception ex)
    {
        var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage($"\nError: {ex.Message}");
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Apr 2025 06:27:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10303039#M16486</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-04-15T06:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader fails with IExtensionApplication</title>
      <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10303058#M16487</link>
      <description>&lt;P&gt;The direct reason that after autoloading your DLL seems not working at all (even you manually run the command "BikubeRibbon", you obviously got "unknown command" error) is that you DID NOT use try...catch... to handle possible exception in the Initialize() method, where you run a fairly complicated code (to build you custom ribbon tab/items), which could cause runtime error, if not coded well, and in your case, the code does indeed cause error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If exception in Initialize() is not caught, the DLL loading would fail, thus code written in the dll would not work. So, ALWAYS place code in Initialize() in a try...catch... block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now about why your code fails:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When your DLL is loaded on AutoCAD startup, you cannot guarantee that AutoCAD has already finishes its Ribbon menu creation when your DLL is loaded. So, the first line of your code in BikubeRibbon() would raise exception if AutoCAD's RibbonControl has not been available at the time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should start your custom ribbon building process in&amp;nbsp; the event handler of either RibbonServices.RibbonPaletteSetCreated event or Application.Idle event.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 16:02:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10303058#M16487</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-05-10T16:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader fails with IExtensionApplication</title>
      <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10304348#M16488</link>
      <description>&lt;P&gt;Thank you for the tip.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:26:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10304348#M16488</guid>
      <dc:creator>christian.hestnes</dc:creator>
      <dc:date>2021-05-11T05:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Autoloader fails with IExtensionApplication</title>
      <link>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10304350#M16489</link>
      <description>&lt;P&gt;Thank you for the thorough explanation.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:29:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autoloader-fails-with-iextensionapplication/m-p/10304350#M16489</guid>
      <dc:creator>christian.hestnes</dc:creator>
      <dc:date>2021-05-11T05:29:03Z</dc:date>
    </item>
  </channel>
</rss>

