wideman1926
asked on
Thread.CurrentPrincipal Casting Problem
The code Thread.CurrentPrincipal as IChatPrinciple) returns null. IChatPrinciple extends IPrincipal, but a conversion error still occurs. I've been upgrading my application from .net 2.0 to .net 4.0. The .net 2.0 app did not an issue with the code, and I'm at a loss as to what IIS (version 6) settings could be causing this. Any help would be much appreciated. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're not understanding what I am saying : )
You are trying to cast from one derived type to another derived type. This cannot be done. You can cast each derived type to IPrinciple, but you cannot cast between two derived types.
Technically speaking, we are talking about casting to an interface, not a base class.
You are trying to cast from one derived type to another derived type. This cannot be done. You can cast each derived type to IPrinciple, but you cannot cast between two derived types.
Technically speaking, we are talking about casting to an interface, not a base class.
Think of it in this example.
We have a base class Employee. We extend it in two classes: SalariedEmployee and HourlyEmployee. I can cast a SalariedEmployee to be an Employee, and I can cast an HourlyEmployee to be an Employee. Does it make sense that I should be able to cast a HourlyEmployee to be a SalariedEmployee?
We have a base class Employee. We extend it in two classes: SalariedEmployee and HourlyEmployee. I can cast a SalariedEmployee to be an Employee, and I can cast an HourlyEmployee to be an Employee. Does it make sense that I should be able to cast a HourlyEmployee to be a SalariedEmployee?
ASKER
No it doesn't. I didn't write the code. I'm just trying to figure out how to make it work in .net 4.0. Anyway, I'm curious, though, Why did the code work in the .net 2.0 application? It gets run constantly, so it's not an issue of it not being reached.
ASKER