Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 525233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:39:01+00:00 2026-05-13T08:39:01+00:00

I am trying to use System.ComponentModel.TypeConverter to cast a bunch of System.Strings to different

  • 0

I am trying to use System.ComponentModel.TypeConverter to cast a bunch of System.Strings to different types. These Strings may or may not be in a valid format for the TypeConverter, so I’d like to find a way to check their validity before attempting the type conversion (to avoid having to rely on catching a System.FormatException to indicate that the String is not in the correct format).

Great, that’s why TypeConverters have an IsValid() method, right? Well I’m running into a problem where IsValid() will return true, but when I call ConvertFromString(), it throws an exception. Here is some code to reproduce the issue:

        System.ComponentModel.DateTimeConverter DateConversion = 
            new System.ComponentModel.DateTimeConverter();

        String TheNumberZero = "0";

        if (DateConversion.IsValid(TheNumberZero))
            Console.WriteLine(DateConversion.
                ConvertFromString(TheNumberZero).ToString());
        else
            Console.WriteLine("Invalid.");

When I run this, the line

Console.WriteLine(DateConversion.
    ConvertFromString(TheNumberZero).ToString());

throws a System.FromatException with the message

0 is not a valid value for DateTime.

What is the purpose of the IsValid() method if not to check the conversion input before attempting a type conversion? Is there some way I can check the String’s validity short of having to catch the FormatException?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:39:01+00:00Added an answer on May 13, 2026 at 8:39 am

    The documentation is your friend:

    The IsValid method is used to validate
    a value within the type rather than to
    determine if value can be converted to
    the given type
    . For example, IsValid
    can be used to determine if a given
    value is valid for an enumeration
    type. For an example, see
    EnumConverter.

    You can write your own
    WillConvertSucceed method by wrapping
    the ConvertTo and ConvertFrom methods
    in exception blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Just a fast question. I am trying to use System.ComponentModel.DataAnnotations in .NET to
Hi ive been trying to use System.Security.Cryptography to encrypt and decrypt a file but
I am trying to use System.Drawing.Drawing2D.GraphicsPath.AddArc to draw an arc of an ellipse starting
I'm trying to use System.Data.Sqlite library, and I'm following the documentation about optimizing inserts
I am trying to use the System.Net.Mail.MailMessage class in C# to create an email
I'm trying to use the System.IO.Log features to build a recoverable transaction system. I
I am trying to use new Google Cloud Messaging system but I have some
I'm trying to use the Rect structure from System.Windows in MonoDevelop, but I can't
Getting system.entrypointnotfoundexception: loadlibrary While trying to use SevenZipLib.dll to uncompress the .7z file containing
I am trying to use net user with c# System.Diagnostics.ProcessStartInfo proccessStartInfo = new System.Diagnostics.ProcessStartInfo(net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.