NullRef Exception in VM or other PC

  • Thread starter Thread starter Fuubah
  • Start date Start date
F

Fuubah

Hi,

my problem is that my addin works fine on my local pc, but on others or my
VM it doesn't work.

I installed my addin though clickOnce.
(i checked that windows installer 3.1 , .net Framework 3.5Sp1, MS Office
2007 Primary Interop Assemblies and Visualstudio-Tools for Office systems 3.0
have to be installed)

i figured out the lines of code, which throw the exception.

Microsoft.Office.Interop.Outlook.Application _outApp = new
Microsoft.Office.Interop.Outlook.Application(); // works

Outlook.AppointmentItem appointment =
(Outlook.AppointmentItem)_outApp.ActiveInspector().CurrentItem; // works only
local

please has anyone an idea why this works local and not on other machines?

Thanks
 
Obvious question, where it doesn't work is there an open item that's active
(ActiveInspector), and is it an appointment item?

If this is a VSTO addin you never, ever should instantiate a new
Outlook.Application object, that won't be trusted and might be a root cause
of your problem. Even if it isn't the problem it's not good practice.

In a VSTO addin you use the ThisAddin.Application.Application object to
assign to your Outlook.Application object. That's a trusted Application
object. Then, all of your other Outlook objects should derive from that,
which will also make them trusted.
 
Hey,

this happen if i open an appointment item.
I handle a formopenevent from my custom form, where i want to get access to
the active outlook object and the active item.

I can get access to the object in that class (or other classes), so i did
this walkaround with the new object may there is a better way to do this ?

How i can get this object in other classes. i cant change the delegate of an
event? So how would you do this.
 
Sorry, I have no idea what you're talking about.

If there is an ActiveInspector() and it's an AppointmentItem as CurrentItem
then I have no idea why you are getting an exception trying to instantiate
it.

You might want to break apart the line that fires the exception and see
exactly what is the null reference:

Outlook.Inspector insp = _outApp.ActiveInspector();
Outlook.AppointmentItem appointment =
(Outlook.AppointmentItem)insp.CurrentItem;

I'd also check to verify that _outApp isn't null.
 
sorry,

you are right,describing problems is not my strength :/ ^^
i try to say it in a other way.

I have a custom fromregion (in the appointment inspector), which has the
function method
"private void xxx_FormRegionShowing(object sender, System.EventArgs e)"

this function fires if i open a new inspector.

You said i should not create a new object of the application, as i did
[new Microsoft.Office.Interop.Outlook.Application();]

So my question is, how do i can get access to the application object in a
code behind from a Form?

of course i cant use "this.Application.Application;"[this is the way in C#]
like in "ThisAddin.Cs"

thanks for your help, i hope my question is more clearly.
 
Are you talking about code running in the form in VBScript code? In any
Outlook form code you have 2 intrinsic objects (trusted): Application for
the Outlook.Application and Item for the actual item the form represents.
You can use those objects for what you want.
 
I do my addin in C#.

You can create custom regions in the normal outlooksurface with VSTO + VS2008.

I figured out my problem, the event fires to late, i make the same with a
button and it works.

Thanks anyway, you always give very good hints which helps much :)
 
Back
Top