Ilya,
I am not sure why retrieving the UserName is not working in your environment
but I don't believe that this is related to the fact that you are not
running as an administrator. In fact, judging from the error message you
have posted, this appears to be due to .NET's security policy. Have you
modified the runtime security policy in any way? Or are you perhaps building
from a network share? It appears that the assembly containing the code
access permission has not been granted the required EnvironmentPermission.
You can verify which permissions have been granted to the assembly by using
the .NET Framework Configuration Tool. Open the console and select 'Runtime
Security Policy', right-click to display the context menu and select
'Evaluate Assembly...', and then browse to locate the assembly containing
the custom attribute and permission. Choose 'View permissions granted to the
assembly' and then 'Next'. This should tell you if the assembly has the
required permissions. At least in my machine, where I believe that the
security policy has not been modified, this yields the 'Unrestricted'
permission set. You can also view which code groups are actually granting
permissions to the assembly by choosing 'View code groups that grant
permissions to the assembly'. This should help you determine why you are not
getting the necessary permissions. In the typical case the assembly should
be receiving it's permissions from the 'My Computer Zone'.
In any case, including the user name in the example, was simply meant to
show that it was possible to embed additional information, other than the
build time, that could only be determined at compile time. I am not really
certain that it serves any useful purpose.
Fernando Tubio
----- Original Message -----
From: "Ilya P. Ryzhenkov" <[EMAIL PROTECTED]>
Sent: Sunday, January 30, 2005 1:42 PM
Subject: Re: Determing time when a assembly was built
Fernando,
Thanks, that's very interesting. But your example didn't work for me out
of the box:
d:\projects\assembly1\assembly2\test.cs(8,2): error CS0647: Error
emitting 'Assembly1.BuildAttribute' attribute -- 'Unexpected exception
processing attribute -- System.Security.SecurityException: Request for
the permission of type
System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
The state of the failed permission was:
<IPermission class="System.Security.Permissions.EnvironmentPermission,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
version="1"
Read="UserName"/>
.'
However, I'm running as non-admin, may be this is the reason. If I
remove Environment.UserName all works fine. So at least getting build
date/time works. Cool!
Sincerely, Ilya Ryzhenkov
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com