473,394 Members | 1,700 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,394 software developers and data experts.

TextWriterTraceListener in app.config executing over a NetworkShare causes FileIOPermission exception

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 in Main and remove the <system.diagnostics> from
the app.config it will run without error.

Why?

I did a "net use Y: \\computer\share" 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.

TextWriterNetwork.cs
<================================================= ==========================
using System;
using System.Diagnostics;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly:FileIOPermissionAttribute(SecurityAction. RequestMinimum,
All="Y:\\Test\\MyListener.log")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyKeyFile(@"..\..\TextWriter.snk")]

namespace TextWriterNetwork
{
class Class1
{
[STAThread]
[FileIOPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
static void Main(string[] args)
{
//TextWriterTraceListener test =
// new TextWriterTraceListener(@"Y:\Test\MyLIstener.log") ;
//Trace.Listeners.Add(test);
Trace.WriteLine("This is a test");
Trace.Flush();
Console.ReadLine();
}
}
}
<================================================= ==========================
app.config
<================================================= ========================== <?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="TextListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="Y:\Test\MyListener.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
<================================================= ==========================
Reminder on how to setup the strong name key...
<================================================= ========================== sn -k TextWriter.snk
<================================================= ==========================
The exception that I get.
<================================================= ========================== Unhandled Exception: System.Configuration.ConfigurationException: Exception
in configuration section handler (Y:\Test\TextWriterNetwork.exe.config line
3) --
-> System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.Security.SecurityException: Request
for
the permission of type System.Security.Permissions.FileIOPermission,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed.
at
System.Security.SecurityRuntime.FrameDescHelper(Fr ameSecurityDescriptor
secDesc, IPermission demand, PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(Per missionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, In
t32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission
cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at System.Diagnostics.TextWriterTraceListener..ctor(S tring fileName)

The state of the failed permission was:
<IPermission class="System.Security.Permissions.FileIOPermissio n, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Append="Y:\Test\MyListener.log"/>

--- End of inner exception stack trace ---
at System.Reflection.RuntimeConstructorInfo.InternalI nvoke(BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
isBin
derDefault)
at System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at
System.Diagnostics.DiagnosticsConfigurationHandler .HandleListeners(Hashtable
config, XmlNode listenersNode, Object context)
at
System.Diagnostics.DiagnosticsConfigurationHandler .HandleTrace(Hashtable
config, XmlNode traceNode, Object context)
at System.Diagnostics.DiagnosticsConfigurationHandler .Create(Object
parent, Object configContext, XmlNode section)
at
System.Configuration.ConfigurationRecord.EvaluateR ecursive(IConfigurationSec
tionHandler factory, Object config, String[] keys, Int32 iKey, XmlTextReade
r reader)
--- End of inner exception stack trace ---
at
System.Configuration.ConfigurationRecord.EvaluateR ecursive(IConfigurationSec
tionHandler factory, Object config, String[] keys, Int32 iKey, XmlTextReade
r reader)
at System.Configuration.ConfigurationRecord.Evaluate( String configKey)
at System.Configuration.ConfigurationRecord.ResolveCo nfig(String
configKey)
at System.Configuration.ConfigurationRecord.GetConfig (String configKey)
at
System.Configuration.DefaultConfigurationSystem.Sy stem.Configuration.IConfig
urationSystem.GetConfig(String configKey)
at System.Configuration.ConfigurationSettings.GetConf ig(String
sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetCon figTable()
at System.Diagnostics.DiagnosticsConfiguration.Initia lize()
at System.Diagnostics.DiagnosticsConfiguration.get_In dentSize()
at System.Diagnostics.TraceInternal.InitializeSetting s()
at System.Diagnostics.TraceInternal.get_Listeners()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Trace.WriteLine(String message)
at TextWriterNetwork.Class1.Main(String[] args) in
d:\playground\oneoffs\textwriternetwork\textwriter network.cs:line 32
<================================================= ==========================

Jul 21 '05 #1
0 3774

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

Similar topics

5
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...
6
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>...
0
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...
0
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...
0
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." ...
6
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...
5
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...
2
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...
1
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...
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?
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
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,...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.