471,338 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 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 3624

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Sean Feldman | last post: by
6 posts views Thread by schaf | last post: by
5 posts views Thread by alf | last post: by
reply views Thread by rosydwin | last post: by

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.