In VB using ByRef works, but in C# it does not!
I found the solution: out in, ref out 
For the ones like me in yesterday..
using Inventor; //autodesk.inventor.interop
private Inventor.Application m_App = null;
private Inventor.ApplicationEvents m_ApplicationEvents = null;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
//Inventor.Application application = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
m_App = InitializeInventor(true, true);
if (m_App != null)
{
m_ApplicationEvents = m_App.ApplicationEvents;
m_App.ApplicationEvents.OnActivateDocument += ApplicationEvents_OnActivateDocument;
m_App.ApplicationEvents.OnQuit += ApplicationEvents_OnQuit;
}
else
System.Environment.Exit(0);
}
catch
{ }
}
void ApplicationEvents_OnQuit(EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
switch (BeforeOrAfter)
{
case EventTimingEnum.kBefore:
//Do Something;
HandlingCode = HandlingCodeEnum.kEventNotHandled;
break;
default:
HandlingCode = HandlingCodeEnum.kEventNotHandled;
break;
}
}
//Use out instead of ref
void ApplicationEvents_OnActivateDocument(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
HandlingCode = HandlingCodeEnum.kEventNotHandled; //This line is Important
if ((BeforeOrAfter == Inventor.EventTimingEnum.kBefore))
{
//Do Something
}
}Tags:
"Inventor Application Events"
"Handling Inventor Events Using C#"
"Inventor OnActvateDocument"
"ApplicationEventsSink_OnActivateDocumentEventHandler"