I am exporting the Contacts from Office365 using Microsoft.Exchange.WebServices. I have the ContactSchema.Department property working but the same code is throwing exception for the ContactSchema.Birthday field.
The exception occurs in the line:
Microsoft.Exchange.WebServices.Data.Contact.Birthday
The exception is something like get_birthday() threw an exception
I have the following code to get a contact:
Contact c = Contact.Bind(service, Items[i].Id, new PropertySet(ContactSchema.Body, ContactSchema.Birthday));
Any idea of how we have to handle the Birthday field?
That error means the property wasn't set on the Contact. Birthday is an optional property which means if it hasn't been set so no value with be returned. Because its a DateTime value it can't be null, while HasValue should also work to test for this some of plumbing in the EWS Managed API doesn't appear to work as it should. So what i would recommend testing for property first using TryGetProperty which will always work without throwing an exception eg.
Object BirthDayValue = null;
if (c.TryGetProperty(ContactSchema.Birthday,out BirthDayValue))
{
Console.WriteLine(BirthDayValue);
}
Cheers
Glen
Related
I am reading continuous emails from the exchange server and processing their attachments. I have seen various examples of the same but I still get error
You must load or assign this property before you can read its value
My code is as below
ItemView itemView = new ItemView(NoEmailProcess);
itemView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
FindItemsResults<Item> searchResults = service.FindItems(folder.Id, itemView);
foreach (var item in searchResults)
{
if (item is EmailMessage)
{
item.Load();
try
{
// Process my email
}
catch
{
// error
}
}
}
The thing to note is that I dont get this error every time. I get it 10% of times and never during debugging
I was wondering should I use 'Bind' before the 'Load'?
EmailMessage.Bind
Not sure what the problem could be. Could someone please help with areas I should investigate?
An exception with the message "You must load or assign this property before you can read its value" is thrown if you attempt to read a property which isn't present on Item.
The Items returned by service.FindItems contain only some properties. Though the property ItemSchema.HasAttachments is returned for an Item, the property ItemSchema.Attachments is missing. Thus you can only check if there are attachments present on an Item. But trying to read them at once will throw the shown exception.
Before you can read the property ItemSchema.Attachments you need to load it first, You can do it by ItemSchema.Bind or ItemSchema.Load. Both calls result in a GetItem request.
Since a GetItem request returns the property ItemSchema.Attachments too (see the linked MS doc above) you are safe to read it.
I am new to c# and sql database. I got a problem when I request data using LINQ from my local database.
my code is like this:
CorporateActionEventType myEventType = (from en in m_db.m_EventTypes
where en.CorporateActionEventType1 == myCorporateActionEvent.EventType
select en).FirstOrDefault();
CAMAIL_PaymentOptions_vw myPaymentOptions = (from po in m_db.m_PaymentOptions
where po.EventID == myCorporateActionEvent.EventID
select po).FirstOrDefault();
CorporateActionEventType, CAMAIL_PaymentOptions_vw is a class I defined to request data from data base. This is LINQ code. I am really not familiar with that.
ArgumentNullException unhandled error occurred.
From a glance it looks like you may not be instantiating CorporateActionEventType correctly, try using "new".
It may help to post the error message or tell us where exactly you are getting the null exception.
I have the following code which is intended to fetch a list of all the user of an organisation.
public static IEnumerable<Member> ListTrelloUsers()
{
var serializer = new ManateeSerializer();
TrelloConfiguration.Serializer = serializer;
TrelloConfiguration.Deserializer = serializer;
TrelloConfiguration.JsonFactory = new ManateeFactory();
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
TrelloAuthorization.Default.AppKey = ApplicationKey;
TrelloAuthorization.Default.UserToken = GrandToken;
var myOrganization = Member.Me.Organizations.FirstOrDefault().Id; //Exception thrown here.
var orgToAddTo = new Organization(myOrganization);
return orgToAddTo.Members.AsEnumerable();
}
But I'm getting a
System.MissingMethodException
thrown on
RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, Byte[], System.String)
So why is this exception thrown and what should the correctly working code look like?
Clarifications
I will also accept working C#/ASP.Net MVC code that isn't based on Manatee.Trello as an answer. (Including pure API-calls.)
I have tried using the Organisation ID directly as
var orgToAddTo = new Organization(OrganisationId);
but that just caused the same exception to be thrown later when I make a call to the method's returned object (e.g. using Count()).
UPDATE: I tried setting the build to Release instead of Debug and now the (same) exception is instead thrown at
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
This is an issue with RestSharp that I reported quite some time ago, though they deny that it's a problem. If you're using .Net 4.5+, you can try the Manatee.Trello.WebApi package instead of Manatee.Trello.RestSharp.
TrelloConfiguration.RestProvider = new WebApiClientProvider();
Here's my Trello card for tracking the issue. This and this are the RestSharp issues I created.
I have been able to recreate this as well, but have received no help from them to resolve it.
Apperently, the class with missing method is located in an assembly, which differ from the one, which you used while compiling the project. Double check and make sure both at compiling and at execution you use the same assembly with the aforementioned class.
That is my best clue based on the info you've provided.
basically, check project references and make sure, you use correct ones for the class-holding assembly.
This is a .NET error:
Error Message: String was not recognized as a valid Boolean.
Error Source : mscorlib
This may be a bit cryptic-sounding but that's all I have to show. How to go about retracing what happened... I really need help on this, how can this come up if it didn't appear before, though the application was the same.
thanks
This error occurs when using bool.Parse() and the input into the method is not convertible to a boolean value of true/false.
For instance:
string testBool = "true";
bool validBool = bool.Parse(testBool);
// this passes fine
testBool = "asdf";
validBool = bool.Parse(testBool);
// Exception: String was not recognized as a valid Boolean.
If you're using .NET 4.0 or higher, you can use bool.TryParse() instead; it will not throw the exception if it receives invalid input. Otherwise, wrap the statement in a try / catch to consume it.
couple of days back i have used the same code to go to each and every page, today it doesn't work. Does anyone know an other approach than this:
var browser = new IE("http//www.xyz.com");
foreach (Link l in browser.Links)
{
Console.WriteLine(l.Url);
if (l.Url.IndexOf("javascript") == -1)
{
browser.GoTo(l.Url);
browser.WaitForComplete();
Thread.Sleep(200);
browser = IE.AttachTo<IE>(Find.ByUrl(browser.Url));
browser.Back();
}
}
error Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
A NullReferenceException means that you are trying to call a method or access a field/property of a null object. You need to step through this code and figure out what is null when it shouldn't be using the debugger.