473,237 Members | 1,111 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,237 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 3740

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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.