Click here to Skip to main content
16,017,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done all the steps in my Microsoft Lab book (70-536) Lab 6.3

My problem is with the following code:


C#
static void Main(string[] args)
        {
            MainClass objMain = new MainClass();
            Console.WriteLine("----VERIFYING TRUST LEVEL ----");
            objMain.FindPermissionLevel();
            Console.Read();

        }



I looked on MSDN and could not find an assembly reference to get MainClass to work, also there was no class 'MainClass' defined in the example, here is the example right out of the book:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//using System.Collections.Generic;
using System.Reflection;
using System.Security;
using System.Security.Policy;

using System.Collections;


namespace WorkingOnApplicationDomainPrivileges
{
    class Program
    {
        static void Main(string[] args)
        {
            MainClass objMain = new MainClass();
            Console.WriteLine("----VERIFYING TRUST LEVEL ----");
            objMain.FindPermissionLevel();
            Console.Read();

        }

        private void FindPermissionLevel()
        {
            bool isFullTrust = true;
            IEnumerator policy = SecurityManager.PolicyHierarchy();
            while (policy.MoveNext())
            {
                PolicyLevel currentLevel = (PolicyLevel)policy.Current;
                CodeGroup codeGrp = currentLevel.ResolveMatchingCodeGroups(Assembly.GetExecutingAssembly().Evidence);

                isFullTrust = IsFullTrustPolicyLevel(codeGrp, currentLevel);

                if (isFullTrust)
                {
                    Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Full trust mode");
                }
                else
                {
                    Console.WriteLine("/t Policy Level: " + currentLevel.Label + " - Not in trust mode");
                }
            }
        }

        private bool IsFullTrustPolicyLevel(CodeGroup group, PolicyLevel level)
        {
            bool success = false;
            NamedPermissionSet nps = level.GetNamedPermissionSet(group.PermissionSetName);

            if (nps.Name == "FullTrust")
            {
                success = true;
            }
            else
            {
                success = false;
            }

            return success;
        }
    }
}



My question is how do I wright a MainClass to get this to work?

ps this is done in a console application.

There have been so many errors in these books, some of which I was able to solve myself, as for the rest I have only CodeProject to thank.
Both Microsoft, and the publishing house Wiley provide no support for the poor quality of these books.

Thanks in advance...
Posted
Updated 28-Aug-11 2:33am
v2
Comments
Sergey Alexandrovich Kryukov 28-Aug-11 17:55pm    
OP Commented:

The only website the provide is www.wiley.com/college/microsoft

When I followed the link for this book there were no resources available

http://eu.wiley.com/WileyCDA/WileyTitle/productCd-EHEP001589,miniSiteCd-MOAC.html

If there is a Microsoft site that provides solution to these Lab questions I was not able to find it. On the cover it even says Microsoft Official Academic Course.

I don't understand how a book of this nature can make it to print with so many errors without providing a support system to find the solutions to these errors.
Microsoft really need to rethink their strategy with concerns to their "Microsoft Official Academic Course" books. I know I am only a student, but if I can spot the errors...surely their professionals could do a better job.
Sergey Alexandrovich Kryukov 28-Aug-11 18:01pm    
You're not supposed to post non-solution as a solution, so I removed it. At the same time your rightful comment on the quality of the books has its own value, so I moved it here to comments.
Please, next time use "Improve question", "Add comment" or reply to existing comment.

I could only advice to avoid lousy books (if you're sure it's full of errors) and address to MSDN. Maybe, this is a trend, unfortunately. I saw many mistakes in some books myself, even though I rarely read them. A book is already bough, this is all what publishers need; and the system of reviews and support of reputation of books is too weak.
--SA
censurl 29-Aug-11 6:17am    
My apologies I am still new to the site, and can now see how things are done...
The book we are using is a prescribed textbook which was given to all the students. Going to skip the rest of this lab, and move onto lab 7.

Found the solution:

change the line:

MainClass objMain = new MainClass();


To match the name of the MainClass of the application, in this case "Program" which is the default name:

Program objMain = new Program();


thanks...
 
Share this answer
 
Does the book offer a site to download the code? Maybe you can do that instead of typing everything in manually. If it *does* provide a download site, the downloaded code *should* contain everything required to allow the code to compile.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900