Unhandled SecurityException

G

Guest

I have created a console application in C# that appears to not even really
get started unless the code group in which it is contained is set to
FullTrusted. The Everything permission set does not even work. The
application never gets started far enough to get into any of my resource
usage (which is several FileIOPermission's). I do not have any assembly
level Permissions defined, and all of my FileIOPermission usages are
imperative.

The exact error message is:

Unhandled Exception: System.Security.SecurityException: Request failed.
at MyApp.Main(String[] args)
Additional information: Request failed.

I am running this from the command-line, not from the IDE.
 
G

Guest

I did a little further testing and developed a small console application that
reproduces the problem:

using System;
using System.Diagnostics;

namespace Class1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
// Set of required command-line options
class Tes123
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Diagnostics.FileVersionInfo versionInfo =
FileVersionInfo.GetVersionInfo("%systemroot%\\Notepad.exe");
Console.WriteLine(versionInfo.FileVersion);

}
}
}

If you comment out the GetVersionInfoLine (and place something else in the
WriteLine statement), you do not get the originally stated exception.
 
K

Kevin Yu [MSFT]

Hi James,

Thanks for your repro code. I tested it on my machine, however, it gave me
a FileNotFound exception. I made some changes to your code, and it works
fine on my machine.

string s = Environment.GetEnvironmentVariable("systemroot");
System.Diagnostics.FileVersionInfo versionInfo =
FileVersionInfo.GetVersionInfo(s + "\\Notepad.exe");
Console.WriteLine(versionInfo.FileVersion);

I think there might be some incorrect settings on you machine. I suggest
you try to use Microsoft .NET Framework 1.1 Configuration to check for the
required permission set for your assembly. Here are the steps:

1. Open Microsoft .NET Framework 1.1 Configuration in Administrative Tools.
2. In the left tree, select Runtime Security Policy.
3. Click Evaluate assembly from the right pane.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

I left off the most important detail. The application runs as long as the
assembly is unsigned, or is delay-signed. Once I "fully" sign this app, it
produces the error mentioned in my original message.
 
G

Guest

And making sure I give every detail this time...

After signing the assembly, I create a code group in the .NET Configuration
Tool under the User node, that uses Strong Name as the evidence. It is in
this code group that I have to set FullTrust (vs. everything, or some subset)
to get the app to run.
 
K

Kevin Yu [MSFT]

Hi James,

I followed your steps to add a new code group and assigned FullTrust or
Everything permission set to this code group. However, your code still
works fine on my machine. Have you tried to reproduce this with another
clean machine?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi James,

It seems that the .NET framework 2.0 requres full trust. I was testing on
the .NET framework 1.1.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

I am testing with the 1.1 Framework. I have the code group for the assembly
set to Exclusive ("this policy level will only have the permissions from the
permission set associated with this code group"). If I don't set that
property the assembly maintains Unrestricted trust and still runs.
 
K

Kevin Yu [MSFT]

Hi James,

Thanks for noticing me of checking this option. Now finally, I get this
issue reproed. Based on my research, the FileVersionInfo class requires
full trusted permission on the machine. If you use a .NET reflector to
check this class definition, you'll see the following attribute before the
definition.

[PermissionSet(SecurityAction.LinkDemand, Unrestricted=true)]

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top