O
Ole Hanson
Hi
Trying to cast an exception to the correct type, I encounter some "strange"
experiences:
The compiler complains that the variable "t" is unknown in line 2 (Exception
trueException = (t)exception; )!
Why? I am getting the correct System.Type information in line 1 (Type t =
exception.GetType()
, but I can't cast my "trueException" to the correct
type...
Please, give me some input on this..
Thanks!!
/Ole
/// <summary>
/// Extract the property information and add it to the Stringbuilder.
/// </summary>
/// <param name="builder">the builder to populate</param>
/// <param name="exception">the excepton to investigate</param>
private void ExtractExceptionProperties(ref StringBuilder builder, Exception
exception)
{
Type t = exception.GetType();
Exception trueException = (t)exception; //here I want to cast the passed
in System.Exception to the correct type,
if(trueException == null)
return;
PropertyInfo[] aryPublicProperties =
trueException.GetType().GetProperties();
NameValueCollection currentAdditionalInfo;
foreach (PropertyInfo p in aryPublicProperties)
{
do some stuff... (not shown)
..
..
}
Trying to cast an exception to the correct type, I encounter some "strange"
experiences:
The compiler complains that the variable "t" is unknown in line 2 (Exception
trueException = (t)exception; )!
Why? I am getting the correct System.Type information in line 1 (Type t =
exception.GetType()

type...
Please, give me some input on this..
Thanks!!
/Ole
/// <summary>
/// Extract the property information and add it to the Stringbuilder.
/// </summary>
/// <param name="builder">the builder to populate</param>
/// <param name="exception">the excepton to investigate</param>
private void ExtractExceptionProperties(ref StringBuilder builder, Exception
exception)
{
Type t = exception.GetType();
Exception trueException = (t)exception; //here I want to cast the passed
in System.Exception to the correct type,
if(trueException == null)
return;
PropertyInfo[] aryPublicProperties =
trueException.GetType().GetProperties();
NameValueCollection currentAdditionalInfo;
foreach (PropertyInfo p in aryPublicProperties)
{
do some stuff... (not shown)
..
..
}