<?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: Raising ExternalEvent stops before Execute method in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/10378582#M46950</link>
    <description>&lt;P&gt;Found one bug:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Assembly.LoadFrom =&amp;gt;&amp;nbsp;Assembly.LoadFile&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.LoadFrom will load old version dll in app domain, while .LoadFile will differenciate dll version and actual content.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Seems I no longer need to change version number, that's great.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Jun 2021 08:00:21 GMT</pubDate>
    <dc:creator>zhuliyi0</dc:creator>
    <dc:date>2021-06-10T08:00:21Z</dc:date>
    <item>
      <title>Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333614#M46941</link>
      <description>&lt;P&gt;Hi, I have an ExternalEvent which I'm raising from a Button_Click event handler. Pretty normal stuff. However, today for some reason when ExternalEvenet is raised Revit is refusing to go to Execute method. By that I mean when I debug and go line by line I can see that when the button is click and Result.Succeed is returned, then the event is raised, which is normal. It then goes to GetName method of my IExternalEventHandler, but after that it just finishes execution and the focus comes back to the Revit UI. It's quite weird as it was working properly a few days ago.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wondering what could possibly trigger this behaviour?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I can see the ExternalEventRequest.Accepted is returned when my event is raised.&lt;/P&gt;&lt;P&gt;My Revit is 2019 and updated. What I have tried so far:&lt;/P&gt;&lt;P&gt;- Restarting Revit&lt;/P&gt;&lt;P&gt;- Restarting Visual Studio&lt;/P&gt;&lt;P&gt;- Creating a new event handler in VS&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;&lt;P&gt;Cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 03:33:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333614#M46941</guid>
      <dc:creator>hzamani</dc:creator>
      <dc:date>2018-10-15T03:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333659#M46942</link>
      <description>&lt;P&gt;I&amp;nbsp;have been trying to isolate the problem and I'm getting some weird and at the same time interesting results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I found so far that when I comment out part of my Execute method, Revit actually does call the method! The part that I commented out was a second Transaction in my event handler. When I went line by line commenting out and uncommenting I can see the the Execute method will be called when my code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    using (Transaction t2 = new Transaction(doc, "Linking Site Model"))
                    {
                        t2.Start();
                        FilePath sitePath = new FilePath(@"C:\Users\hzamani\Desktop\New Template\SITE Mock Template.rvt");
                        RevitLinkOptions revitLinkOptions = new RevitLinkOptions(false);
                        //RevitLinkLoadResult revitLinkType = RevitLinkType.Create(doc, sitePath, revitLinkOptions);
                        //RevitLinkInstance revitLinkInstance = RevitLinkInstance.Create(doc, revitLinkType.ElementId);

                        t2.Commit();
                    }&lt;/PRE&gt;&lt;P&gt;But as soon as I uncomment the two lines which are commented out, the Execute method is not called!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any explanation to why this is happening?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 04:12:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333659#M46942</guid>
      <dc:creator>hzamani</dc:creator>
      <dc:date>2018-10-15T04:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333734#M46943</link>
      <description>&lt;P&gt;&lt;EM&gt;Most probably an exception is thrown in the first command. You could use Exception monitoring in Visual Studio or add try and catch to check what Revit is complaining about.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 05:46:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333734#M46943</guid>
      <dc:creator>cwaluga</dc:creator>
      <dc:date>2018-10-15T05:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333752#M46944</link>
      <description>&lt;P&gt;I do have encapsulated all my code in a try catch block. No exception is thrown. Revit just simply returns to the UI with no action.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 05:55:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8333752#M46944</guid>
      <dc:creator>hzamani</dc:creator>
      <dc:date>2018-10-15T05:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8334105#M46945</link>
      <description>Not sure, but I think Revit catches Exceptions that occur during command invokation. Also, command invokation is always asynchronous. In that case your outer catch block will never catch anything.&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Oct 2018 09:30:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8334105#M46945</guid>
      <dc:creator>cwaluga</dc:creator>
      <dc:date>2018-10-15T09:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8336182#M46946</link>
      <description>&lt;P&gt;Turned out it was a junior mistake. I had referenced RevitAPI.dll from Revit 2017 and was testing on Revit 2019. The class name RevitLinkLoadResult has been renamed to LinkLoadResult since Revit 2018, hence not existing in Revit 2019 as well. Because Revit couldn't find the class name it wasn't calling the method which had used this class name.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 23:28:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8336182#M46946</guid>
      <dc:creator>hzamani</dc:creator>
      <dc:date>2018-10-15T23:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8433057#M46947</link>
      <description>&lt;P&gt;I too have this problem now.&amp;nbsp;&lt;BR /&gt;The wierd thing is that sometimes it works and sometimes it doesnt.&amp;nbsp;&lt;BR /&gt;I have wrapped the entire Execute-method in a try catch block and I've set a breakpoint at the first line in the method, but nothing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way of figuring out what is wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 12:53:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8433057#M46947</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-29T12:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8433427#M46948</link>
      <description>&lt;P&gt;I have now commented out the entire Execute-method without any success. It doesnt read the name of the External Event or Invoke the Execute method…&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 14:41:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/8433427#M46948</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-29T14:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/10375817#M46949</link>
      <description>&lt;P&gt;I encountered this issue when using addin manager. It turns out the Execute() method will be skipped if any assembly directly referenced by the method is missing. Addin Manager is supposed to find all the dlls inside the executing directory, and load them all, but for some unknown reason, sometimes it fails to load some dlls. When the code is running inside an external command or external event, there will be "&lt;SPAN&gt;Could not load file or assembly or one of its dependencies" exception thrown. However, if the Execute() method directly calls some missing assembly, there will be no exception thrown, and Revit will just silently continue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My solution: before every external event is raised, register to AppDomain.AssemblyResolve event, and handle the event by manully specify the dll file inside executing directory. Now the execute() method no longer skips. This also solves all the&amp;nbsp;"Could not load file" errors if assembly resolve event is handled during the whole execution. I unregister it after execute method is finished.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Havn't done lots of testing though.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And here is my simple class for register and handling seembly resolve event:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static class AssemblyLoader&lt;BR /&gt;{&lt;BR /&gt;private static bool registered = false;&lt;BR /&gt;public static void Register(bool _register)&lt;BR /&gt;{&lt;BR /&gt;if (_register == registered)&lt;BR /&gt;return;&lt;BR /&gt;if (_register)&lt;BR /&gt;AppDomain.CurrentDomain.AssemblyResolve += onAssemblyResolve;&lt;BR /&gt;else&lt;BR /&gt;AppDomain.CurrentDomain.AssemblyResolve -= onAssemblyResolve;&lt;/P&gt;&lt;P&gt;registered = _register;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;private static Assembly onAssemblyResolve(object sender, ResolveEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;var name = args.Name;&lt;BR /&gt;name = name.SplitBy(",").First();&lt;BR /&gt;var fullName = args.RequestingAssembly.FullName;&lt;BR /&gt;string path = args.RequestingAssembly.Location;&lt;BR /&gt;path = Path.GetDirectoryName(path);&lt;BR /&gt;path += "\\" + name + ".dll";&lt;BR /&gt;var a = Assembly.LoadFrom(path);&lt;BR /&gt;return a;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 10:19:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/10375817#M46949</guid>
      <dc:creator>zhuliyi0</dc:creator>
      <dc:date>2021-06-09T10:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Raising ExternalEvent stops before Execute method</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/10378582#M46950</link>
      <description>&lt;P&gt;Found one bug:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Assembly.LoadFrom =&amp;gt;&amp;nbsp;Assembly.LoadFile&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.LoadFrom will load old version dll in app domain, while .LoadFile will differenciate dll version and actual content.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Seems I no longer need to change version number, that's great.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 08:00:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/raising-externalevent-stops-before-execute-method/m-p/10378582#M46950</guid>
      <dc:creator>zhuliyi0</dc:creator>
      <dc:date>2021-06-10T08:00:21Z</dc:date>
    </item>
  </channel>
</rss>

