469,289 Members | 2,143 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Apply security permission in class library, fail to call it out!

Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime.InteropServices;
using System.Security.Permissions;

[assembly:IsolatedStorageFilePermission(SecurityAct ion.RequestMinimum,
UserQuota=1048576)]
[assembly:SecurityPermission(SecurityAction.Request Refuse,
UnmanagedCode=true)]
[assembly:FileIOPermission(SecurityAction.RequestOp tional, Unrestricted=true)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Security.SecurityException' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
3 2508
Hi there,

if the exception is being thrown right after you start the app, there should
be a problem with the requested permissions (The RequestMinimum for example
or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of
the requested permissions are being granted. That means that based on the
evidences for the assembly's origin (zone it is being started from, strong
name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will
be trown(which might be a SecurityException or PolicyException - depending
on the case).

Otherwise, if the exception is being thrown after the app starts, you should
try to find where the exception is being trowned - there should be a problem
with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like
the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under
you're trying to start the app or something else - like starting it from a
network location (which is not being detected as local intranet) - in this
case the CAS (code access security) just restricts the permissions to the
app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:E7**********************************@microsof t.com...
Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime.InteropServices;
using System.Security.Permissions;

[assembly:IsolatedStorageFilePermission(SecurityAct ion.RequestMinimum,
UserQuota=1048576)]
[assembly:SecurityPermission(SecurityAction.Request Refuse,
UnmanagedCode=true)]
[assembly:FileIOPermission(SecurityAction.RequestOp tional, Unrestricted=true)]
In AssemblyInfo.cs

[assembly: AssemblyKeyFile("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Security.SecurityException' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)

Nov 16 '05 #2
I had a tester app with a button. Inside the button click function, it will
call the class library with security permission.

It means, when i run the app no problem, just when i click on the button, i
receive the security problem.

Thanks for the previous tip. Do i need to do anything extra on the tester
app? Like coding attributes or doing something to allow me? Or is more to
permission on windows side?

Thanks again.

"Branimir Giurov" wrote:
Hi there,

if the exception is being thrown right after you start the app, there should
be a problem with the requested permissions (The RequestMinimum for example
or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of
the requested permissions are being granted. That means that based on the
evidences for the assembly's origin (zone it is being started from, strong
name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will
be trown(which might be a SecurityException or PolicyException - depending
on the case).

Otherwise, if the exception is being thrown after the app starts, you should
try to find where the exception is being trowned - there should be a problem
with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like
the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under
you're trying to start the app or something else - like starting it from a
network location (which is not being detected as local intranet) - in this
case the CAS (code access security) just restricts the permissions to the
app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:E7**********************************@microsof t.com...
Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime.InteropServices;
using System.Security.Permissions;

[assembly:IsolatedStorageFilePermission(SecurityAct ion.RequestMinimum,
UserQuota=1048576)]
[assembly:SecurityPermission(SecurityAction.Request Refuse,
UnmanagedCode=true)]
[assembly:FileIOPermission(SecurityAction.RequestOp tional,

Unrestricted=true)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Security.SecurityException' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #3
It depends -

if there is a permission denied from the OS (like file permission) it should
throw an exception as well. You can do something else - try to do a security
demand in the class library before accessing a resource. Before the demand,
write into the debuger or the trace, then do the same after the deman. The
security demand will wall the call stack and make sure that the callers have
the the same permissions as well as the one you're asking for. For example:

Trace.WriteLine("before demand permission to ...");
FileIOPermission fp = new FileIOPermission(FileIOPermissionAccess.Read,
"c:\\test.txt");
fp.Demand();
Trace.WriteLine("after demand permission to ...");

You should do that if you can't debug the source with VS. By doing this, you
can intercept where the exception comes from. The other possible solution is
to compile in a Debug mode and catch the permission at app level. Then log
the stack trace and the message. By looking at the stack trace, you'll see
in which method the exception was thrown originally.

Let me know how it goes. :)

Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:CC**********************************@microsof t.com...
I had a tester app with a button. Inside the button click function, it will call the class library with security permission.

It means, when i run the app no problem, just when i click on the button, i receive the security problem.

Thanks for the previous tip. Do i need to do anything extra on the tester
app? Like coding attributes or doing something to allow me? Or is more to
permission on windows side?

Thanks again.

"Branimir Giurov" wrote:
Hi there,

if the exception is being thrown right after you start the app, there should be a problem with the requested permissions (The RequestMinimum for example or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of the requested permissions are being granted. That means that based on the evidences for the assembly's origin (zone it is being started from, strong name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will be trown(which might be a SecurityException or PolicyException - depending on the case).

Otherwise, if the exception is being thrown after the app starts, you should try to find where the exception is being trowned - there should be a problem with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under you're trying to start the app or something else - like starting it from a network location (which is not being detected as local intranet) - in this case the CAS (code access security) just restricts the permissions to the app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:E7**********************************@microsof t.com...
Hi there,

I had applied this security permissions in my class library based on fxcop standards.

Before namespace:

using System.Runtime.InteropServices;
using System.Security.Permissions;

[assembly:IsolatedStorageFilePermission(SecurityAct ion.RequestMinimum,
UserQuota=1048576)]
[assembly:SecurityPermission(SecurityAction.Request Refuse,
UnmanagedCode=true)]
[assembly:FileIOPermission(SecurityAction.RequestOp tional,

Unrestricted=true)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile("../../snkey.snk")]

But when my windows app try to all the function during run time, it just fails.

The errors:

An unhandled exception of type 'System.Security.SecurityException' occured in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Olaf Baeyens | last post: by
29 posts views Thread by Patrick | last post: by
1 post views Thread by Jason | last post: by
19 posts views Thread by Diego F. | last post: by
5 posts views Thread by Henry Stock | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.