Exception thrown: 'Autodesk.Revit.Exceptions.InternalException' in RevitAPI.dll

Exception thrown: 'Autodesk.Revit.Exceptions.InternalException' in RevitAPI.dll

mabbasT3S75
Explorer Explorer
3,287 Views
3 Replies
Message 1 of 4

Exception thrown: 'Autodesk.Revit.Exceptions.InternalException' in RevitAPI.dll

mabbasT3S75
Explorer
Explorer

I was debugging my add-in when I got the following error.

 

Exception thrown: 'Autodesk.Revit.Exceptions.InternalException' in RevitAPI.dll
An exception of type 'Autodesk.Revit.Exceptions.InternalException' occurred in RevitAPI.dll but was not handled in user code
No valid type for the assembly instance.

 

I googled about Internal Exception and learned from thebuildingcoder.com that Internal Exceptions are to be passed back to Autodesk for diagnostics.

 

The error occurred at this location in my code:

AssemblyInstance assemblyInstance = AssemblyInstance.Create(doc, collection, categoryId);
assemblyInstance.AssemblyTypeName = assemblyInteger.ToString();

Any help will be much appreciated!

0 Likes
Accepted solutions (1)
3,288 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Are you using a transaction to create the assembly instance? I am guessing that is needed. This can be done like this:

 

using (Transaction tx = new Transaction(doc))
{
   
tx.Start("Creating Assembly Instance"); AssemblyInstance assemblyInstance = AssemblyInstance.Create(doc, collection, categoryId);
assemblyInstance.AssemblyTypeName = assemblyInteger.ToString();
tx.Commit(); }

 

Also, you can use a try/catch statement to retrieve more information about the crash:

try
{

   AssemblyInstance assemblyInstance = AssemblyInstance.Create(doc, collection, categoryId);
assemblyInstance.AssemblyTypeName = assemblyInteger.ToString(); } catch (Exception ex) { TaskDialog.Show("Crash",ex.message);
throw; }

 

I hope this helps

0 Likes
Message 3 of 4

mabbasT3S75
Explorer
Explorer

Yes, I have used a transaction. Again the purpose of try-catch is to find the error but it will not tell you at what line does the error occur. A debugger is good for identifying the exact location of the error. The specific error is:

 

"No valid type for the assembly instance." 

 

According to the Revit API, AssemblyInstance.Create() should return type AssemblyInstance but that gives me an error, as noted in my question.  

0 Likes
Message 4 of 4

mabbasT3S75
Explorer
Explorer
Accepted solution

@Anonymous Thanks for trying to help me out. So I figured out what was going wrong. The thing is that when the assembly instance was created, Revit did not know it has been created because the changes were never committed and it was left wondering at the next line, what on earth is this assembly instance the user is talking about. This was fixed quite easily by just committing the changes before modifying the newly created assembly instance.

So here is the final solution to your code with some modifications:

using (Transaction tx = new Transaction(doc))
{
   
   tx.Start("Creating Assembly Instance");
   AssemblyInstance assemblyInstance = AssemblyInstance.Create(doc, collection, categoryId);
   tx.Commit();
   tx.Start("Modify assemblyInstance");
   assemblyInstance.AssemblyTypeName = assemblyInteger.ToString();
   tx.Commit();

}

Thanks once again for trying to help me out.

Cheers mate!

 

0 Likes