troubleshooting Question

help!! my .exe running on my box but not on someother box in LAN

Avatar of Venkatesh Velugubantla
Venkatesh Velugubantla asked on
14 Comments1 Solution249 ViewsLast Modified:
Hi all..
  I have a problem.  I have the following peice of code:

using System;
using System.IO;
using System.Security.Permissions;
using System.Reflection;

namespace FileonLan

      class Class1
            static void Main(string[] args)
                  string path = @"\\PC1\New Folder\temp.txt";
                        if (!File.Exists(path))
                              // Create a file to write to.
                              using (StreamWriter sw = File.CreateText(path))
                        // Open the file to read from.
                        using (StreamReader sr = File.OpenText(path))
                              string s = "";
                              while ((s = sr.ReadLine()) != null)

                  catch (Exception ex)


this is running fine when I run it from my pc. but if I copy the executable to any computer in my LAN, its giving the following error

System.Security.SecurityException: Request for the permission of type System.Sec
urity.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutra
l, PublicKeyToken=b77a5c561934e089 failed.
   at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet granted
Set, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permT
   at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, S
tackCrawlMark& 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 bFr
   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 encodin
g, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at System.IO.File.CreateText(String path)
   at FileonLan.Class1.Main(String[] args)

i've serached on google and found that the following liks are the most  useful links for me,guid,4c5a21b0-dfa7-4947-ac76-ee4b3e12e020.aspx

but even after going through those links, I am not able to rectify the problem.. can anyone help me??
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros