Value does not fall within the expected range.

Add-in Express™ Support Service
That's what is more important than anything else

Value does not fall within the expected range.
Value does not fall within the expected range. 
Ramanujam Mariappan




Posts: 2
Joined: 2008-10-31
Hi Guys,

I was developing an add-in to save an email selected in the outlook. This add-in has been used in both Visual Studio 2005 and 2008. Whenever i am trying to save an email, i getting the following exception, on the add-in installed on building in Visual Studio 2005

System.ArgumentException: Value does not fall within the expected range.
at AddinExpress.Outlook.IOutlookSecurityManager2.Connect(Object vTarget)
at AddinExpress.Outlook.SecurityManager.ConnectTo(Object outlookApp)

This works fine in Visual Studio 2008. Is there any difference between the Add-in developed in Visual Studio 2005 and 2008. I have pasted the code base for your reference. Please throw light on this issue.


#region [ThisApplication_Startup]
/// <summary>
/// Invoked when the Host application gets loaded (OUTLOOK)
/// </summary>
/// <value></value>
private void ThisApplication_Startup(object sender, System.EventArgs e) {
//Create a trusted Application Object - make sure you derive all relevent object from this
//otherwise security warning dialog will be triggered when acessing the
//Outlook restricted property.
oApp = this.Session.Application as Application;
//Initialize the Event tracker
try {
//TODO - Currently the approach supports only Windows Authentication, so we are
//getting the username from the WindowsIdentity, and password is null
//If we need to support both , we need to get the username and password from the form
username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
int slashindex = username.IndexOf(@"\");
username = username.Substring(slashindex + 1, username.Length - slashindex - 1);
helper = new OutlookSynchHelper();
//Check whether the user is a valid user,
//if user is valid user, build the PHUZE menus
if (this.ValidateUser(username, null)) {
//Get the Permission
helper.GetUserPermissions(username);
//Build the CommandBar
this.BuildCommandBar();
//Add button to the Command Bar
this.AddButtonToCommandBar();
//Create menu
this.CreateMenu();
//Check whether the user has permission to save email
if (!helper.Authorize(PermissionConstants.CRMAdavanced.Email.SAVE_EMAIL)) {
//Disable all the menus to save an email
this.DisablePhuzeMenus();
}
}
} catch (System.Exception ex) {
//Logs the exception
OutlookSettingsHelper.LogException(ex);
MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Properties.Resources.MenuBuildError));
}
}
#endregion


private void phuzeEmailSaveButton_Click(CommandBarButton Ctrl, ref bool CancelDefault) {
BaseResponse response = new BaseResponse(ResponseState.DatabaseFailure);
SecurityManager securityManager = null;
try
{
MailItem mailDetails;
// Get the MAPI namespace.
NameSpace oNS = oApp.GetNamespace("MAPI");
try
{
securityManager = new SecurityManager();
securityManager.ConnectTo(this.Session.Application);
securityManager.DisableCDOWarnings = true;

}
catch (ApplicationException e)
{
HandleOutlookSecurityManagerException(e);
}
catch (COMException e)
{
HandleOutlookSecurityManagerException(e);
}
//Gets the list of selected items
Selection selection = oApp.ActiveExplorer().Selection;
Posted 31 Oct, 2008 12:03:14 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hello Ramanujam,

Did you try to debug? Please make sure that the Application object is not null.

Did you start to develop your add-in with VSTO 2005 (SE) (Visual Studio 2005) or VSTO 3 (Visual Studio 2008)?
.NET, Extended MAPI, Windows Phone & RT
Posted 01 Nov, 2008 07:41:15 Top
Ramanujam Mariappan




Posts: 2
Joined: 2008-10-31
Hi Eugene

We have started the development in VSTO 2005, then moved on to VSTO 2008.
Since we have relased our earlier version which was developed in VSTO 2005, so that we need to support both versions


Thanks
Ramanujam
Posted 01 Nov, 2008 07:52:09 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Ramanujam,

Please make sure that the Application object is not null.
.NET, Extended MAPI, Windows Phone & RT
Posted 01 Nov, 2008 08:05:48 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25

And try to use the following code:


securityManager = new SecurityManager();
securityManager.ConnectTo(this.Session.Application);
securityManager.DisableOOMWarnings = true;
.NET, Extended MAPI, Windows Phone & RT
Posted 01 Nov, 2008 08:07:22 Top