API Contact Form Issue

Highlighted
Solution Provider

API Contact Form Issue

Hello,


I'm using the Visual Studio ASPSample solution and after editing the AddContactSmallForm.aspx and viewing it I'm receiving the following error message when adding a contact through the ASPSample.sln.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.



Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.



Source Error:











Line 961: ? ContactEmailTypeHtml
Line 962: : emailTypeNames);
Line 963: data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames);
Line 964: data.AppendFormat("<Note>{0}</Note>", contact.Note);
Line 965: data.AppendFormat("<CustomField1>{0}</CustomField1>", contact.CustomField1);



Source File: C:\Documents and Settings\Albert\My Documents\Downloads\NET_ASP Upload Forms_1\ASP Upload Forms\Development\ConstantContactUtility\Components\ContactComponent.cs    Line: 963


Is there something I'm doing wrong? I'm able to get the compiled web sample to work without any problems.


Thanks for your help.

2 REPLIES 2
Highlighted
Moderator

It appears that the project

It appears that the project is unable to find the entry for contact.OPtInSource in the optSourceNames dictionary.  Have you checked the available values for optSourceNames and the current value for contact.OptInSource to confirm everything matches?  When running the unmodified sample, all opt in source values do work for the project on our test servers.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Moderator

I just compared your code

I just compared your code with the default code and noticed that there is a potential issue.  The default code has the followin line at 963:


 


data.AppendFormat("<OptInSource>{0}</OptInSource>", optSourceNames);


 


This is one of the valid opt in source options (other is ActionByCustomer).  If you are creating a contact, this is the correct way to populate the data.  The way you are using the code would be for updating a contact that already exists.  It looks like the way you're running the code, the dictionary index value will probably end up being null (since the new contact doesn't have an opt in source yet as it's now).  Try changing that line back to the original code value of the ContactOptSource.ActionByCustomer value and the error should go away.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured