473,770 Members | 7,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextWriterTrace Listener in app.config executing over a NetworkShare causes FileIOPermissio n exception

I am at a loss as to why this is not working. I am trying to setup a
TextWriterTrace Listener in my application config file and then execute the
app from the network. I get a security exception (listed below) even though
I have StrongNamed my application and used the .NET Configuration Tool to
create a Code Access Group in the Machine Policy that gives FullTrust to
assemblies with the StrongName that I created.

If you uncomment the code in Main and remove the <system.diagnos tics> from
the app.config it will run without error.

Why?

I did a "net use Y: \\computer\shar e" to setup my execution location.

I am wondering if this is just a bug with .NET or I need to find the magic
setting somewhere to get things to work...

Please help.

TextWriterNetwo rk.cs
<============== =============== =============== =============== =============== =
using System;
using System.Diagnost ics;
using System.Security .Permissions;
using System.Reflecti on;
using System.Runtime. CompilerService s;

[assembly:FileIO PermissionAttri bute(SecurityAc tion.RequestMin imum,
All="Y:\\Test\\ MyListener.log" )]
[assembly: AssemblyVersion ("1.0.0.0")]
[assembly: AssemblyKeyFile (@"..\..\TextWr iter.snk")]

namespace TextWriterNetwo rk
{
class Class1
{
[STAThread]
[FileIOPermissio nAttribute(Secu rityAction.Dema nd, Unrestricted=tr ue)]
static void Main(string[] args)
{
//TextWriterTrace Listener test =
// new TextWriterTrace Listener(@"Y:\T est\MyLIstener. log");
//Trace.Listeners .Add(test);
Trace.WriteLine ("This is a test");
Trace.Flush();
Console.ReadLin e();
}
}
}
<============== =============== =============== =============== =============== =
app.config
<============== =============== =============== =============== =============== = <?xml version="1.0"?>
<configuratio n>
<system.diagnos tics>
<trace autoflush="fals e" indentsize="4">
<listeners>
<add name="TextListe ner"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "Y:\Test\MyList ener.log"/>
</listeners>
</trace>
</system.diagnost ics>
</configuration>
<============== =============== =============== =============== =============== =
Reminder on how to setup the strong name key...
<============== =============== =============== =============== =============== = sn -k TextWriter.snk
<============== =============== =============== =============== =============== =
The exception that I get.
<============== =============== =============== =============== =============== = Unhandled Exception: System.Configur ation.Configura tionException: Exception
in configuration section handler (Y:\Test\TextWr iterNetwork.exe .config line
3) --
-> System.Reflecti on.TargetInvoca tionException: Exception has been thrown by
the target of an invocation. ---> System.Security .SecurityExcept ion: Request
for
the permission of type System.Security .Permissions.Fi leIOPermission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9 failed.
at
System.Security .SecurityRuntim e.FrameDescHelp er(FrameSecurit yDescriptor
secDesc, IPermission demand, PermissionToken permToken)
at System.Security .CodeAccessSecu rityEngine.Chec k(PermissionTok en
permToken, CodeAccessPermi ssion demand, StackCrawlMark& stackMark, Int32
checkFrames, In
t32 unrestrictedOve rride)
at System.Security .CodeAccessSecu rityEngine.Chec k(CodeAccessPer mission
cap, StackCrawlMark& stackMark)
at System.Security .CodeAccessPerm ission.Demand()
at System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean
bFromProxy)
at System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize)
at System.IO.Strea mWriter.CreateF ile(String path, Boolean append)
at System.IO.Strea mWriter..ctor(S tring path, Boolean append, Encoding
encoding, Int32 bufferSize)
at System.IO.Strea mWriter..ctor(S tring path, Boolean append)
at System.Diagnost ics.TextWriterT raceListener..c tor(String fileName)

The state of the failed permission was:
<IPermission class="System.S ecurity.Permiss ions.FileIOPerm ission, mscorlib,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
version="1"
Append="Y:\Test \MyListener.log "/>

--- End of inner exception stack trace ---
at System.Reflecti on.RuntimeConst ructorInfo.Inte rnalInvoke(Bind ingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
isBin
derDefault)
at System.Reflecti on.RuntimeConst ructorInfo.Invo ke(BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at
System.Diagnost ics.Diagnostics ConfigurationHa ndler.HandleLis teners(Hashtabl e
config, XmlNode listenersNode, Object context)
at
System.Diagnost ics.Diagnostics ConfigurationHa ndler.HandleTra ce(Hashtable
config, XmlNode traceNode, Object context)
at System.Diagnost ics.Diagnostics ConfigurationHa ndler.Create(Ob ject
parent, Object configContext, XmlNode section)
at
System.Configur ation.Configura tionRecord.Eval uateRecursive(I ConfigurationSe c
tionHandler factory, Object config, String[] keys, Int32 iKey, XmlTextReade
r reader)
--- End of inner exception stack trace ---
at
System.Configur ation.Configura tionRecord.Eval uateRecursive(I ConfigurationSe c
tionHandler factory, Object config, String[] keys, Int32 iKey, XmlTextReade
r reader)
at System.Configur ation.Configura tionRecord.Eval uate(String configKey)
at System.Configur ation.Configura tionRecord.Reso lveConfig(Strin g
configKey)
at System.Configur ation.Configura tionRecord.GetC onfig(String configKey)
at
System.Configur ation.DefaultCo nfigurationSyst em.System.Confi guration.IConfi g
urationSystem.G etConfig(String configKey)
at System.Configur ation.Configura tionSettings.Ge tConfig(String
sectionName)
at System.Diagnost ics.Diagnostics Configuration.G etConfigTable()
at System.Diagnost ics.Diagnostics Configuration.I nitialize()
at System.Diagnost ics.Diagnostics Configuration.g et_IndentSize()
at System.Diagnost ics.TraceIntern al.InitializeSe ttings()
at System.Diagnost ics.TraceIntern al.get_Listener s()
at System.Diagnost ics.TraceIntern al.WriteLine(St ring message)
at System.Diagnost ics.Trace.Write Line(String message)
at TextWriterNetwo rk.Class1.Main( String[] args) in
d:\playground\o neoffs\textwrit ernetwork\textw riternetwork.cs :line 32
<============== =============== =============== =============== =============== =

Jul 21 '05 #1
0 3853

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

Similar topics

5
555
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when it is invoked by pressing "F5", or when the web.config file is modified. In all these cases the web.config file contains <identity impersonate="false" />. The mysterious problem arrises when I set <identity impersonate="true"/> in the...
6
2454
by: Sean Feldman | last post by:
Hello, I'm trying to insert TextWriterTraceListener to web.config file, but it fails all the time. This is my web.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation defaultLanguage="c#" debug="true" /> <customErrors mode="RemoteOnly" /> <authentication mode="Windows" />
0
1113
by: **Developer** | last post by:
This is almost the same as a previous post that is still giving me a problem, but with a different slant. I can't seem to find out what is wrong. My program crashes after it leaves an event handler. It is an event that is raised by Net's ListBox. The form handling the event, as described below, contains a UserControl that inherits from ListBox but does not handle nor override the event in question. So the stack contains only the handler...
0
405
by: Ant Corrie | last post by:
I am at a loss as to why this is not working. I am trying to setup a TextWriterTraceListener in my application config file and then execute the app from the network. I get a security exception (listed below) even though I have StrongNamed my application and used the .NET Configuration Tool to create a Code Access Group in the Machine Policy that gives FullTrust to assemblies with the StrongName that I created. If you uncomment the code...
0
1085
by: raju | last post by:
If add the following section to web.config for my ASP.NET, it fails to add listeners at startup and raises exception: "Parser Error Message: Exception in configuration section handler." <system.diagnostics> <trace autoflush="true" indentsize="0"> <listeners> <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="myTrace.txt"/>
6
2476
by: schaf | last post by:
Hi NG ! I have the following piece of code below. the first try/catch part would return true although I do not have permission to access this computer. The second try/catch part would return false. Do I misunderstand the meaning of FileIOPermission ? >From MSDN: "Controls the ability to access files and folders" ??? Thanks for education! Regards Marcel (Schaf)
5
10339
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I get the following error on the page: Security Exception Description: The application attempted to perform an operation not allowed
2
2664
by: | last post by:
I set up a TextWriterTraceListener in the App.config file. I'd like to be able to tell, programmatically, which file it's using. However, I don't seem to be able to get at the initializeData attribute. The Attribute collection attached to the TextWriterTraceListener is empty. Any ideas as to how I might get at this file name without having to parse App.config?
1
2797
by: innes | last post by:
Hi, I'm trying to test permission to access the file system, using FileIOPermission, but can't seem to get it to work. See my sample app below, for an app that tries to demand a permission to read a specified path, and then calls Directory.GetFiles on that path. The Demands on FileIOPermissions (I tried 3 variations) all work, and then when I call Directory.GetFiles an exception is thrown... saying
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.