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.
Related
Hi I'm taking back the lead on a project for an Excel plugin. But I ran into a kind of strange error:
System.Runtime.InteropServices.COMException (0x800A03EC): Parameter not valid at Microsoft.Office.Interop.Excel._Chart.FullSeriesCollection(Object Index)
The corresponding line is:
chart.FullSeriesCollection(1).DataLabels.ShowValue = true;
Any idea of what's wrong in there?
I wonder why it gives me an exception of invalid parameter when i request the details of a file which is a video and want to get its resolution. I use:
var f = service.Files.Get(id);
f.Fields = "VideoMediaMetadata.Height";
var result = f.Execute();
I tried many different ways: "VideoMediaMetadata" without ".Height", "VideoMediaMetadata(height, width)", "VideoMediaMetadata/Height" etc. but nothing worked. When i do this for example:
f.Fields = "id, name, size";
It works fine.
Appreciate the help
It gives off an invalid parameter because GET was expecting a VideoMediaMetadata object resource but you instead tried to access the int values. I suggest passing VideoMediaMetadata as your parameter first and execute the request. After that, parse the response body for the 'height' and 'width' int property.
So using your code above:
f.Fields = "VideoMediaMetadata";
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
I am starting my first project using spacial data. Im using VS 2012 and SQL 2012 I have referenced System.Data.Entity and can use DbGeography in my code but when I try to create a point I get the above error and don't understand why
here is my code
var text = string.Format(CultureInfo.InvariantCulture.NumberFormat,
"POINT({0} {1})", submitted.Long, submitted.Lat);
// 4326 is most common coordinate system used by GPS/Maps
try
{
var wkb = DbGeography.PointFromText(text, 4226);
}
catch (Exception exc)
{
}
the syntax that OP has used is correct, the actual issue that caused this error was the SRID, 4226 is not a known SRID, But you already knew this. because it is in your comment :)
A one line example of the correct usage in your scenario would be:
var wkb = DbGeography.PointFromText($"POINT({submitted.Long} {submitted.Lat})", 4326);
Where did you go wrong though? Whenever you get a
System.Reflection.TargetInvocationException
With a message of
Exception has been thrown by the target of an invocation
You must immediately check the Inner Exception for the details on the actual error, in this case it is outlined clearly for you:
24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view.
I realise that this is an old thread, but IMO this is an example of second most common .Net developer issue that people keep posting on SO. Please read through your full exception stack before pulling your hair out.
I'm just guessing, but I reckon NullReferenceException issues would be the most common :)
is wrong to order the lat and long
the correct is:
DbGeography.PointFromText(POINT(lat long), 4226);
Complete class:
public static DbGeography CreatePoint(double latitude, double longetude, int srid = 4326)
{
var lon = longetude.ToString(CultureInfo.InvariantCulture);
var lat = latitude.ToString(CultureInfo.InvariantCulture);
var geo = $"POINT({lat} {lon})";
return DbGeography.PointFromText(geo, srid);
}
Call:
CreatePoint(-46.55377, 23.11817)
I have a OdbcDataReader that gets data from a database and returns a set of records.
The code that executes the query looks as follows:
OdbcDataReader reader = command.ExecuteReader();
while (reader.Read())
{
yield return reader.AsMovexProduct();
}
The method returns an IEnumerable of a custom type (MovexProduct). The convertion from an IDataRecord to my custom type MovexProduct happens in an extension-method that looks like this (abbrev.):
public static MovexProduct AsMovexProduct(this IDataRecord record)
{
var movexProduct = new MovexProduct
{
ItemNumber = record.GetString(0).Trim(),
Name = record.GetString(1).Trim(),
Category = record.GetString(2).Trim(),
ItemType = record.GetString(3).Trim()
};
if (!record.IsDBNull(4))
movexProduct.Status1 = int.Parse(record.GetString(4).Trim());
// Additional properties with IsDBNull checks follow here.
return movexProduct;
}
As soon as I hit the if (!record.IsDBNull(4)) I get an OverflowException with the exception message "Arithmetic operation resulted in an overflow."
StackTrace:
System.OverflowException was unhandled by user code
Message=Arithmetic operation resulted in an overflow.
Source=System.Data
StackTrace:
at System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
at System.Data.Odbc.OdbcDataReader.IsDBNull(Int32 i)
at JulaAil.DataService.Movex.Data.ExtensionMethods.AsMovexProduct(IDataRecord record) [...]
I've never encountered this problem before and I cannot figure out why I get it. I have verified that the record exists and that it contains data and that the indexes I provide are correct. I should also mention that I get the same exception if I change the if-statemnt to this: if (record.GetString(4) != null). What does work is encapsulating the property-assignment in a try {} catch (NullReferenceException) {} block - but that can lead to performance-loss (can it not?).
I am running the x64 version of Visual Studio and I'm using a 64-bit odbc driver.
Has anyone else come across this? Any suggestions as to how I could solve / get around this issue?
Many thanks!
For any one experiencing the same issue, the way I solved this was to switch from the Odbc* classes to their OleDb* counterparts. This of course demands that your data driver has support for OleDb connections.
Which DB are you trying to talk to? If it uses some "private" column types that can cause problems. That doesn't apply to SQL Server of course :-)
Also check that you are compiling and running as x64 (Process Explorer will show you thsi and even plain tack manager shows it). devenv.exe will still be x86 but your actual binary should run as x64. The reason I mention is that crossing 32/64 bit boundary is notorious for breaking 3rd party ODBC drivers.