Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

calling of Revit API from external application not workin in C#

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
4436 Views, 2 Replies

calling of Revit API from external application not workin in C#

Hi,

 

I use to call the revit api from external application and was working around 2 years before but if I use the same call its failing .

 

Exception is .....

 

System.BadImageFormatException was unhandled
FileName=RevitAPIUI.dll
FusionLog=""
HResult=-2147023898
Message=Could not load file or assembly 'RevitAPIUI.dll' or one of its dependencies. Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
Source=COMPAS_BIM
StackTrace:
at COMPAS_BIM.Drawing3D.Genearate3DDrawings()
at COMPAS_BIM_Client.Program.Main(String[] args) in D:\Revit\COMPAS_BIM_Client\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: Anonymous

Dear Krisnx,

 

Thank you for your query.

 

Calling directly into the Revit API from an external context is, was and always has been illegal.

 

If you were doing so successfully in the past, you were putting yourself and all your users at severe risk of file corruption and data loss.

 

The Revit API cannot ever be used except within a valid Revit API context.

 

Such a context is provided exclusively by Revit call-back methods.

 

You need to subscribe to a Revit event, such as an external command Execute method.

 

Within the event handler, the Revit API can be used.

 

You can also use the Revit API to set up an external event that can be raised from a non-Revit-API context, such as your standalone external application.

 

This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent SDK sample.

 

A large number of examples and further explanations are provided in The Building Code topic group on Idling and External Events for Modeless Access and Driving Revit from Outside:

 

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

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Message 3 of 3
jeremytammik
in reply to: Anonymous

Don't miss the update on this topic here:

 

http://thebuildingcoder.typepad.com/blog/2017/05/external-access-to-the-revit-api.html

 

Cheers,

 

Jeremy



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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community