NullRefrenceException when using ISelectionFilter before selection is attempted

NullRefrenceException when using ISelectionFilter before selection is attempted

KevinEliteCAD
Participant Participant
1,055 Views
4 Replies
Message 1 of 5

NullRefrenceException when using ISelectionFilter before selection is attempted

KevinEliteCAD
Participant
Participant

Hi, 

I've been using this ISelectionFilter class  to filter point clouds before selection based on the Autodesk Documentation and it was working fine until this morning. Now when I try to use any of the classes that reference the selection filter I get a null reference exception before a selection is even attempted. Without fail it automatically throws the error when it gets the the line in the code that calls it.

I'm using Revit 2020.4 and Visual Studio Community 2019. I ran a build of the app from yesterday and the methods all work perfectly fine. I looked throw my Github and the files havent been changed since last week. I have no idea why now I'm getting this exception when it seems like I'm following the documentation.

kevin_0-1628595487958.png

kevin_1-1628595498664.png

 

 

0 Likes
Accepted solutions (1)
1,056 Views
4 Replies
Replies (4)
Message 2 of 5

AGGilliam
Collaborator
Collaborator
Accepted solution

Based on the error you're getting, it looks like your mouse is hovering over an element without a valid category when you get to that point in the code (no clue what that could be). To get around that, I would add this before your return statement: 

if (e.Category is null)
return false;

 It's usually best to add the variable to your watchlist in debug mode to see what values you're actually getting as well so you can better prepare for them.

Message 3 of 5

KevinEliteCAD
Participant
Participant
that seemed to do it! not sure why this was happening. There was nothing but a point cloud and some levels in my project and I tried it in a new project as well.
0 Likes
Message 4 of 5

AGGilliam
Collaborator
Collaborator

Something I've noticed with the ISelectionFilters is that you occasionally come across elements you wouldn't expect. Whenever I get an error like that, the first thing I do is debug and check the name of the element that's throwing the error to see what I'm actually hovering over and make sure the values I'm checking are all valid.

0 Likes
Message 5 of 5

NonicaTeam
Enthusiast
Enthusiast

That was really helpful! Thanks

0 Likes