Inconsistent Exception: Exceptions.InternalException occurred in RevitAPI.dll

Inconsistent Exception: Exceptions.InternalException occurred in RevitAPI.dll

thomas
Advocate Advocate
4,139 Views
14 Replies
Message 1 of 15

Inconsistent Exception: Exceptions.InternalException occurred in RevitAPI.dll

thomas
Advocate
Advocate

I have been experiencing a very peculiar exception in one of my apps which throws the following exception:

 

An exception of type 'Autodesk.Revit.Exceptions.InternalException' occurred in RevitAPI.dll but was not handled in user code
Additional information: A managed exception was thrown by Revit or by one of its external applications

 

The reason why it is so peculiar is because it is inconsistent. For example, the same process will work, then if the inputs to the process are refreshed (i.e. the exact same test conditions), the exception is thrown. 

 

I'll break the steps down to elaborate:

 

- I am creating a ElementIntersectsSolidFilter

- The input solid is derived from an element in a Revit link which itself is wrapped in my own class

- The filter is evaluated against elements in the active model

- The program executes within a Dynamo custom node

 

I've isolated the problem to the solid input to the filter. Since the problem was inconsistent - for example, if i input a list of elements from the linked model, extracted each elements solids and input them into the filter, the exception could occur with any of the elements at any time - I tried a simple test: use a try catch around the filter and if the exception is thrown, recreate the filter using the exact same inputs. With this simple workaround (and test), the few occasions where the exception is thrown is now caught, and so far everything is working as expected. 

 

Has anyone experienced similar issues with the ElementIntersectsSolidFilter before and can anyone explain this odd behaviour. Why is it inconsistent? Why, when the exception does occur, does it only occur once per 'problem' solid?

0 Likes
Accepted solutions (1)
4,140 Views
14 Replies
Replies (14)
Message 2 of 15

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

Thank you for your report.

 

I agree that this is strange.

 

One aspect of this is that the Revit API should never leak an InternalException.

Can you possibly provide a minimal reproducible case for the development team to analyse?

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 15

thomas
Advocate
Advocate

Hi Jeremy 

 

Thanks for your reply - I've created a simplified example which consistently reproduces the exception. 

 

The test conditions are:

 

- Revit 2018.2

- Dynamo 1.3.2

 

As the exception is thrown via a Dynamo node, I have created two nodes (included in a graph as part of the test-case files) one which includes the try catch I mentioned (therefore works as expected) and another which does not and throws the managed exception.

 

I have some confidential files to send - is it best to raise a ticket through my Autodesk subscription to send the files securely?

0 Likes
Message 4 of 15

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

An ADN case has already been generated from this thread for you.

 

Its number is 13816574 [Inconsistent Exception: Exceptions.InternalException occurred in RevitAPI.dll].

 

Please attach your confidential information to that case.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 15

thomas
Advocate
Advocate

Thanks Jeremy 

 

I've provided the files and look forward to the response from the development team

 

Regards

 

Tom 

0 Likes
Message 6 of 15

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

Thank you for the reproducible case.

 

I logged the issue REVIT-126020 [Inconsistent InternalException using ElementIntersectsSolidFilter -- 13816574] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 15

thomas
Advocate
Advocate

Hi Jeremy 

 

Thanks for logging the issue. 

 

  • Impact on your application and/or your development:

Mild - the workaround is acceptable for the time being, however, given that its a peculiar exception, I am keen to find a resolution in case it escalates into a more severe exception which cant be adequately handled or which impacts negatively on my programs performance. 

 

 

  • The number of users affected

250+

 

 

  • Realistic timescale over which a fix would help you

3 Months

 

 

  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address

Interference Checking in Revit that extends its own Interference Checker with the ability to check link elements vs link elements and variations thereof

 

 

Regards

 

Tom 

0 Likes
Message 8 of 15

jeremytammik
Autodesk
Autodesk

Dear Tom,

 

Thank you for your business case, which I added to the issue REVIT-126020 [Inconsistent InternalException using ElementIntersectsSolidFilter -- 13816574].

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 15

thomas
Advocate
Advocate

Hi Jeremy

 

I notice that the case opened for this has been closed when I check it on my Autodesk Account, but no details have been added. Is this normal, and will there be a response from the development team re this issue?

 

Regards

 

Tom 

0 Likes
Message 10 of 15

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Tom,

 

Thank you for your update.

 

Whether the associated ADN case is open or closed makes no difference whatsoever as long as we are aware of its existence and case number.

 

You can open, update and add any new information you wish to it at any time you like regardless.

 

Furthermore, the status of the ADN case in no way affects the internal development issue REVIT-126020 [Inconsistent InternalException using ElementIntersectsSolidFilter -- 13816574]. The development team only care about the latter.

 

I just had some feedback from them on that as well, saying:

 

I dived into this issue recently and found the exception thrown in ElementIntersectsFilter.PassesFilter method in attached project due to the solid geometries object (managed object) being released by the .NET GC(Garbage Collection) Finalizer thread. This will happen when a lot of .NET objects have been created and exceed the threshold value of .NET GC.

 

One way to resolve this is to keep a reference of the solid object in the scope of ElementIntersectsFilter.PassesFilter method. Here is the customer's code to reproduce this issue, and I replaced the commented line defining the defaultFilter with the following lines to keep the solid as reference in the same scope. That ought to fix the issue:

 

  public static List<List<DynamoElement>> ExceptionThrown(
    List<DynamoElement> inheritedElements,
    List<DynamoElement> elements,
    DynamoCoordinateSystem transform)
  {
    Document doc = DocumentManager.Instance.CurrentDBDocument;
    Transform revitTransform = transform.ToTransform();
    List<List<DynamoElement>> intersectingElementsResultList = new List<List<DynamoElement>>();
    foreach (InheritedElement e in inheritedElements)
    {
      RevitElement eRevit = e.InternalElement;
      List<DynamoElement> intersectingElements = new List<DynamoElement>();
      //ElementIntersectsFilter defaultFilter = Filter.InheritedElementFilter(e, eRevit, revitTransform);
      Solid solid = Filter.ExtractSolids(eRevit);
      Solid solidToLinkCentre = SolidUtils.CreateTransformed(solid, revitTransform);
      ElementIntersectsFilter defaultFilter = new ElementIntersectsSolidFilter(solidToLinkCentre);
      BoundingBoxXYZ bb = eRevit.get_BoundingBox(null);
      Outline outline = new Outline(bb.Min, bb.Max);
      List<DynamoElement> subElements = Filter.GetSurrounding(outline, elements);
      for (int j = 0; j < subElements.Count; j++)
      {
        DynamoElement eB = subElements[j];
        bool result = false;
        result = defaultFilter.PassesFilter(eB.InternalElement);
        if (result) intersectingElements.Add(eB);
      }
      intersectingElementsResultList.Add(intersectingElements);
    }
    return intersectingElementsResultList;
  }

 

Can you test whether that resolves the problem for you?

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 11 of 15

thomas
Advocate
Advocate

Hi @jeremytammik 

 

Thank you for the response, this is invaluable knowledge and very useful - its good to get detailed information on the precise cause and a solution. 

 

Regards

 

Tom 

0 Likes
Message 12 of 15

jeremytammik
Autodesk
Autodesk

Dear Tom,

 

Thank you for your update and appreciation.

 

I totally agree  🙂

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 13 of 15

MattKincaid
Advocate
Advocate

@jeremytammikThanks for the solution.  Could you please clarify something about it for me?  We see a similar error sometimes with the VB code below.

 

    Public Iterator Function GetElementsIntersectingSolid(document As Document,
                                                          solid As Solid,
                                                          phase As Phase,
                                                          categories As ICollection(Of ElementId),
                                                          ignoreElements As ICollection(Of ElementId),
                                                          elementIdSet As ICollection(Of ElementId)) As IEnumerable(Of Element)

        If solid Is Nothing Then Exit Function
        Dim outline = solid.GetBoundingBox.GetTransformedOutline

        Using collector = New FilteredElementCollector(document)
            If Not elementIdSet.IsNullOrEmpty Then collector.WherePasses(New ElementIdSetFilter(elementIdSet))
            collector.WherePasses(New BoundingBoxIntersectsFilter(outline))
            collector.WherePasses(New ElementIntersectsSolidFilter(solid))
            If Not categories.IsNullOrEmpty Then collector.WherePasses(New ElementMulticategoryFilter(categories))
            If Not ignoreElements.IsNullOrEmpty Then collector.WherePasses(New ExclusionFilter(ignoreElements))

            'Build output.
            Dim elements = New List(Of Element)

            For Each element In collector

                Yield element

            Next

        End Using

    End Function

 

Based on your answer, it sounds like we should change the code to use PassesFilter, rather than the WherePasses method on the FilteredElementCollector.  Do you think the code below would resolve the error?  It's difficult to test, since we also see this error only inconsistently.  Thank you!

 

    Public Iterator Function GetElementsIntersectingSolid2(document As Document,
                                                          solid As Solid,
                                                          phase As Phase,
                                                          categories As ICollection(Of ElementId),
                                                          ignoreElements As ICollection(Of ElementId),
                                                          elementIdSet As ICollection(Of ElementId)) As IEnumerable(Of Element)

        If solid Is Nothing Then Exit Function
        Dim outline = solid.GetBoundingBox.GetTransformedOutline

        Dim f = New ElementIntersectsSolidFilter(solid)

        Using collector = New FilteredElementCollector(document)
            If Not elementIdSet.IsNullOrEmpty Then collector.WherePasses(New ElementIdSetFilter(elementIdSet))
            collector.WherePasses(New BoundingBoxIntersectsFilter(outline))
            If Not categories.IsNullOrEmpty Then collector.WherePasses(New ElementMulticategoryFilter(categories))
            If Not ignoreElements.IsNullOrEmpty Then collector.WherePasses(New ExclusionFilter(ignoreElements))

            'Build output.
            Dim elements = New List(Of Element)

            For Each element In collector

                If f.PassesFilter(element) Then
                    Yield element
                End If

            Next

        End Using

    End Function

 

0 Likes
Message 14 of 15

jeremytammik
Autodesk
Autodesk

What is the purpose of this code, please?

 

`InternalException` should not be exposed at all, afaik.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 15 of 15

MattKincaid
Advocate
Advocate

@jeremytammikIt's pretty similar to the purpose of the original poster's code.  The goal is to get all the model elements which intersect an arbitrary solid. 

0 Likes