Solved

Thread.CurrentPrincipal Casting Problem

Posted on 2011-03-11
5
313 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:wideman1926
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35112146
You can't cast between two derived types--you can only cast to a common base type (or interface). You should be able to cast Thread.CurrentPrincipal to IPrincipal.
0
 

Author Comment

by:wideman1926
ID: 35112265
Thread.CurrentPrincipal is IPrinciple, which is the base class of the class that I'm casting to.  You can cast from a base to a derived class.  Plus, the application that this code is a part of works and is used heavily.  The application will not work if that line of code fails.  It worked fine in 2.0, but is failing in .net 4.0.  That's what's perplexing me.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35112372
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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35112401
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?
0
 

Author Comment

by:wideman1926
ID: 35112450
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
coded character set iptc field within a jpeg 1 70
WKHTMLTOPDF - --disable-smart-shrinking not working 10 37
Host asp.net pages 5 25
SQL Exceptions 3 39
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now