TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jasminie
NA
78
0
C#.net object reference error
Aug 31 2011 5:32 PM
How you tell me how to change the C#.net desktop 2008 logic so it will compile clean and the logic works? The problem is I am trying to create an instance of an object in a static class
In this application I want to create a 'class with methods for accessing the active directory' from all parts of the solution file. As part of this logic change when a user clicks on the desktop shortcut and they are not assigned to any active directory groups, I want to throw an error message stating 'do not have access-contact network administrator and throw them out of the application.
The logic to check the user credentials comes from the main method that is a 'static' method in program.cs.
The code I want to add to the main methos is as follows:
ActiveDirectoryUser CurUser;
CurUser = new ActiveDirectoryUser();
However I get the following errors:
-
Error 55 'Desktop.CurUser': cannot declare instance members in a static class
Error 56 The type or namespace name 'ActiveDirectoryUser' could not be found (are you missing a using directive or an assembly reference?)
Error 57 The type or namespace name 'ActiveDirectoryUser' could not be found (are you missing a using directive or an assembly reference?)
The cLass i want to reference looks like the following:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Threading;
using System.Web;
using System.Windows.Forms;
using System.Security.Principal;
namespace EnrollTrac.Common
{
public class ActiveDirectoryUser
{
public ActiveDirectoryUser()
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if ((!Thread.CurrentPrincipal.IsInRole("testit")))
{
MessageBox.Show("You do not have authortity.Please contact your network administrator"," Error", essageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
Application.Run(new Desk());
break;
}
Reply
Answers (
2
)
Synchronizing two SQL tables
How comparing database table rows using nested loop?