COMAddin AccessViolationException on ItemSendEvent

Jan 2, 2012 at 7:36 PM

Hi!,

I wanted to connect the ItemSendEvent in my test application.

_outlookApplication.ItemSendEvent += _outlookApplication_ItemSendEvent;

Every time this line is executed I get an AccessViolationException.

The EventBridgeInitialized member has the value false. I think that's the problem.

What do I have to do to solve this Probem?

I use:

System: windows7 64bit

.Net: 4.0, Visual Studio 2010 with c#

Office 2010 64-bit

NetOffice Release 1.3.2

Thank you.

SGabor

Coordinator
Jan 2, 2012 at 11:10 PM
Edited Jan 2, 2012 at 11:10 PM

sounds not good. my x86 test works fine, give me 2 hours to create a x64 test.

 *Sebastian

Coordinator
Jan 2, 2012 at 11:57 PM

my x64 test works also fine. do you have a more detailed code snippet for me?

here is my code:

private void Test()
{
   LateBindingApi.Core.Factory.Initialize();

   Outlook.Application application = new Outlook.Application();
   application.ItemSendEvent += new  Outlook.Application_ItemSendEventHandler(application_ItemSendEvent);
   application.Quit();
   applicatition.Dispose();
}

private void application_ItemSendEvent(COMObject Item, ref bool Cancel)
{

}

*Sebastian

Coordinator
Jan 3, 2012 at 3:08 PM

do you have a COM Addin?

Jan 3, 2012 at 3:16 PM

Dear Sebastian,

Thanks for the quick response, I'm currently not at home, i will try tonight your snippet


SGabor

Jan 3, 2012 at 4:29 PM

Hi,

Yes i have a COM Addin,

I've tried your snippet, unfortunately still occurs AccessViolationException,

Here is my snippet:

        void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                // Initialize NetOffice
                LateBindingApi.Core.Factory.Initialize();

                //Initializing
                _outlookApplication = new Outlook.Application(null, Application);
                _outlookNameSpace = _outlookApplication.GetNamespace("MAPI");

                // Subscribe the events
                _outlookApplication.ItemSendEvent += new Outlook.Application_ItemSendEventHandler(Application_ItemSendEvent);
            }
            catch (Exception ex)
            {

            }
        }

        private void Application_ItemSendEvent(COMObject Item, ref bool Cancel)
        {
            if (Item == null)
                return;

            try
            {
                if (Item is Outlook.MailItem)
                {
                }
            }
            catch (Exception ex)
            {
               
            }
        }

 

Thank you

SGabor

Coordinator
Jan 3, 2012 at 5:33 PM

i do a test with a x64 compiled addin, win7 x64/office 2010 x64 an it works fine for me.
the exception was thrown at runtime or in the debugger with the option "hold on any exception" ?
its possible you send me your e-mail address in a private message and i send you the solution thats works for me?

*Sebastian

 

 

Jan 3, 2012 at 5:57 PM

Hi,

you have a post on SebastianDotNet


Thanks

Jan 12, 2012 at 10:29 PM
Edited Jan 12, 2012 at 10:32 PM

Hi Sebastian,

I have the same problem. The following code caused an AccessViolationException on "inboxItems.ItemAddEvent += new NetOffice.OutlookApi.Items_ItemAddEventHandler(InboxItems_Add);":

void IDTExtensibility2.OnConnection(
	object Application, 
	ext_ConnectMode ConnectMode, 
	object AddInInst, 
	ref Array custom
)
{
	try
	{
		// Initialize NetOffice
		LateBindingApi.Core.Factory.Initialize();

		//Initializing
		application = new Outlook.Application(null, Application);
		Outlook.MAPIFolder inbox = 
			application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
		
		// Subscribe the events
		inboxItems = (Outlook.Items)inbox.Items;
		inboxItems.ItemAddEvent += 
			new NetOffice.OutlookApi.Items_ItemAddEventHandler(InboxItems_Add);
	}
	catch
	{
	}
}

private void InboxItems_Add(
	COMObject Item
)
{
	[...]
}

Do you have an idea of this problem?

Coordinator
Jan 12, 2012 at 11:01 PM

NetOffice Release 1.4 is available in 2 hours. i change the CreateEventBridge() implementation and add bool Settings.EnableDebugOutput.
i hope the problem is resolved and i in case of any trouble we can see what happens with the debug output.
i found one mistake in GetConnectionPoint :(

 

string id = id =FindConnectionPoint(connectionPointContainer, ref point, sinkIds);

fixed in NetOffice 1.4 !

*i'm sorry for that.

Coordinator
Jan 13, 2012 at 2:10 AM

NetOffice 1.4 [beta] is now available in the download section.(upload in progress currently)
please give me a response the issue is resolved or not.
when aready was okay i can publish this release as stable.

*sebastian

Feb 15, 2012 at 3:58 PM

Hello,

I have to apologize my late feedback. But I needed a quite long time to find out why each NetOffice-Addin did not work. Now it seems that everything works well.

The problem was that mscoree.dll was set as a "DisabledItem":

After I deleted each key under HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Resiliency\DisabledItems everything works well.

In conclusion: Your beta version seems good! I have no error left.

Thanks again for your great development!!!

Coordinator
Feb 15, 2012 at 5:05 PM

hello there,

the discussion about Shimming is interesstent for you maybe: http://netoffice.codeplex.com/discussions/285331
the problem is office can's see an .net assembly, the host application see only the mscoree.dll when a .NET addin cause a critical error,
then the mscoree.dll was disabled and all .Net addin assemblies are disabled. for these reason you can create a COM Shim, means an unmanaged C++ proxy addin.
the proxy addin are loaded from the office app. at these time the proxy addin loads your addin. i hope i can create an optional available SHIM behaviour in the future for COM Addins based on NetOffice.