473,408 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Getting noddy CAS example working

Hi
I'm stuck with the basics of CAS. I have a solution with two
projects, Assembly1 and Assembly2. Assembly1 is happily making calls
to the registry, filesystem, etc

Assembly1 calls a method on Assembly2, in the AssemblyInfo file for
Assembly2 I have these lines:

[assembly: AllowPartiallyTrustedCallers]
[assembly: FileIOPermission(SecurityAction.RequestMinimum, Read = @"D:
\temp\temp.txt")]
[assembly: FileIOPermission(SecurityAction.RequestOptional, Read = @"D:
\temp\temp.txt")]

and I have in a method

FileStream s = File.Open(@"D:\temp\temp.txt", FileMode.Open);

When I run this I get an error on that line which says
"Request for the permission of type
System.Security.Permissions.FileIOPermission (etc) failed]

If I remove the AssemblyInfo lines and just add this
[assembly: FileIOPermission(SecurityAction.RequestOptional, Read = @"D:
\temp\temp.txt", Unrestricted = true)]

then it works. I don't understand.
(1) Why do I need unrestricted access? I just want to read the file
(2) I though if you use RequestOptional it meant that you also needed
AllowPartiallyTrustedCallers for any calling assembly

please help, spent hours on this and I haven't a clue
Sep 19 '08 #1
3 1162
k, I assume its because I did:

FileStream s = File.Open(@"D:\temp\temp.txt", FileMode.Open);

and File.Open can do more than read, if I do this in the assembly:

[assembly: FileIOPermission(SecurityAction.RequestMinimum,All = @"D:
\temp\temp.txt")]
[assembly: FileIOPermission(SecurityAction.RequestOptional, All = @"D:
\temp\temp.txt")]

it works, replacing Read with All, or similiarly this (which to my
mind is clearer)

[assembly: FileIOPermission(SecurityAction.RequestMinimum,All = @"D:
\temp\temp.txt")]
[assembly: PermissionSet(SecurityAction.RequestOptional)]
Sep 19 '08 #2
<co**********@googlemail.comwrote in message
news:71**********************************@m73g2000 hsh.googlegroups.com...
I'm stuck with the basics of CAS. I have a solution with two
projects, Assembly1 and Assembly2. Assembly1 is happily making calls
to the registry, filesystem, etc

Assembly1 calls a method on Assembly2, in the AssemblyInfo file for
Assembly2 I have these lines:

[assembly: AllowPartiallyTrustedCallers]
[assembly: FileIOPermission(SecurityAction.RequestMinimum, Read = @"D:
\temp\temp.txt")]
[assembly: FileIOPermission(SecurityAction.RequestOptional, Read = @"D:
\temp\temp.txt")]

and I have in a method

FileStream s = File.Open(@"D:\temp\temp.txt", FileMode.Open);

When I run this I get an error on that line which says
"Request for the permission of type
System.Security.Permissions.FileIOPermission (etc) failed]

If I remove the AssemblyInfo lines and just add this
[assembly: FileIOPermission(SecurityAction.RequestOptional, Read = @"D:
\temp\temp.txt", Unrestricted = true)]

then it works. I don't understand.
(1) Why do I need unrestricted access? I just want to read the file
(2) I though if you use RequestOptional it meant that you also needed
AllowPartiallyTrustedCallers for any calling assembly

please help, spent hours on this and I haven't a clue
(1) The problem is in the line
FileStream s = File.Open(@"D:\temp\temp.txt", FileMode.Open);
This opens the file for reading AND WRITING, even if your code desn't
write anything to the Stream that you opened. So in the moment of executing
that statement you need read and write permission, which is granted by the
"unrestricted" permission request, but not by the "read" request.

(2) I understand that AllowPartiallyTrustedCallers is only needed in the
called assembly if it has a strong name and if it is being called from a
calling assembly that does not have Full Trust.

Sep 19 '08 #3
Your reply came 2 minutes after my post :-) But thanks, if I hadn't
found it your answer would have been enough for me to sort it

thanks
Sep 19 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Allan Topp | last post by:
I know little to nothing about PHP and need to clarify something before committing to learning it. From what I have heard PHP would be ideal to interrogate a database and populate HTML tables...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Torsten Mohr | last post by:
Hi, based on the example module "noddy" i wrote an own one and i have problems accessing the elements in the python objects. I defined the example object: typedef struct { PyObject_HEAD...
12
by: Gnolen | last post by:
Hi, I am really getting crazy here! I just do not get why this happens with the borders of the td/tr! I just want a border on the bottom of the rows(or td) but I just can't do it!!! I have tried...
0
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the...
0
by: Jim | last post by:
This si a repost, I apologize but perhaps my original inquiry got buried under all the usenet spam... I need some help getting started with a .NET web project for a commercial site. I am new to...
7
by: billr | last post by:
but ireally does need clearing up ... Traditionally (i.e. in C++) I might do the following: SomeObj ptrSomeObj; for(int i = 0; i < iCount; ++i) { ptrSomeObj = new SomeObj();...
28
by: Stefan Mueller | last post by:
I can display the value of the following input box with alert(parent.MyFrame.document.MyForm.MyInput.value); But if the frame, the form or the input box doesn't exist I get of course an error...
11
by: Simon Wigzell | last post by:
My website sends automatic emails from many (25) different places. I want to send a second email by reading the parameters of the first one. I don't want to have to repeat and maintain the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.