Home All Groups Group Topic Archive Search About

Permission Exception.

Author
4 Oct 2006 9:21 AM
Bishman
Hi,

A very small utility app I have written throws an exception "Request for the
permission of type 'System.Net.Mail.S
mtpPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c56
1934e089' failed."

Now the .exe is on a  'D:'  share in a folder.

If I run the .EXE using a UNC path ie
    "\\coventry\data\castleview\utilities\smtp.exe
"jon.sm***@castleins.co.uk" "test" "test""
it throws the error.

If I run the app as
    "D:\castleview\utilities\smtp.exe "jon.sm***@castleins.co.uk" "test"
"test""
I dont get the error....

Can someone point me in the right direction to understand what is causing
this please ?

Many thanks,

Full code listed below !

Jon.

class Program

{

static void Main(string[] args)

{

try

{

const string sSMTPServer = "172.20.50.25";

if (args.Length == 4 || args.Length == 5)

{

string sFromAddress = args[0];

string sToAddress = args[1];

string sSubject = args[2];

string sBody = args[3];

string sAttachmentFile = string.Empty;

if (args.Length == 5)

sAttachmentFile = args[4];

if (sFromAddress.Contains(".") == true && sFromAddress.Contains("@") == true
&& sToAddress.Contains(".") == true && sToAddress.Contains("@") == true)

{

MailMessage message = new MailMessage(sFromAddress, sToAddress, sSubject,
sBody);

if (sAttachmentFile != String.Empty)

{

Attachment data = new Attachment(args[4]);

message.Attachments.Add(data);

}

SmtpClient client = new SmtpClient(sSMTPServer);

try

{

client.Credentials = CredentialCache.DefaultNetworkCredentials;

}

catch (Exception excpt)

{

Console.WriteLine("An error occurred initialising the mail client. " +
excpt.Message + "\n");

}

try

{

client.Send(message);

}

catch (Exception excpt)

{

Console.WriteLine("An error occurred sending the mail. " + excpt.Message +
"\n");

}

}

else

{

Console.WriteLine("Parameter error." + "\n");

ShowParameters();

}

}

else

{

ShowParameters();

}

}

catch (Exception excpt)

{

Console.WriteLine("A horrible error occurred. " + excpt.Message + "\n");

}

}

private static void ShowParameters()

{

Console.WriteLine("SMTP - Version 1.0");

Console.WriteLine("USAGE:");

Console.WriteLine("smtp [From Email Address] | [To Email Address] |
[Subject] | [Body Text] | [Attachment Filename]");

}

}


Request for the permission of type 'System.Net.Mail.S
mtpPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c56
1934e089' failed.

Author
4 Oct 2006 8:42 PM
Petar Repac
Hi, Bishman,

take a look at Code Access Security (CAS)

for example:
1) http://msdn2.microsoft.com/en-us/library/930b76w0.aspx
2) http://www.codeproject.com/dotnet/UB_CAS_NET.asp

When you run your app from a UNC path .NET framework thinks about it
as loading it from a share and default CAS settings don't permit running
code from shares.

Regards,
Petar Repac


Bishman wrote:
Show quote
> Hi,
>
> A very small utility app I have written throws an exception "Request for the
> permission of type 'System.Net.Mail.S
> mtpPermission, System, Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c56
> 1934e089' failed."
>
> Now the .exe is on a  'D:'  share in a folder.
>
> If I run the .EXE using a UNC path ie
>     "\\coventry\data\castleview\utilities\smtp.exe
> "jon.sm***@castleins.co.uk" "test" "test""
> it throws the error.
>
> If I run the app as
>     "D:\castleview\utilities\smtp.exe "jon.sm***@castleins.co.uk" "test"
> "test""
> I dont get the error....
>
> Can someone point me in the right direction to understand what is causing
> this please ?
>
> Many thanks,
>
> Full code listed below !
>
> Jon.
>
> class Program
>
> {
>
> static void Main(string[] args)
>
> {
>
> try
>
> {
>
> const string sSMTPServer = "172.20.50.25";
>
> if (args.Length == 4 || args.Length == 5)
>
> {
>
> string sFromAddress = args[0];
>
> string sToAddress = args[1];
>
> string sSubject = args[2];
>
> string sBody = args[3];
>
> string sAttachmentFile = string.Empty;
>
> if (args.Length == 5)
>
> sAttachmentFile = args[4];
>
> if (sFromAddress.Contains(".") == true && sFromAddress.Contains("@") == true
> && sToAddress.Contains(".") == true && sToAddress.Contains("@") == true)
>
> {
>
> MailMessage message = new MailMessage(sFromAddress, sToAddress, sSubject,
> sBody);
>
> if (sAttachmentFile != String.Empty)
>
> {
>
> Attachment data = new Attachment(args[4]);
>
> message.Attachments.Add(data);
>
> }
>
> SmtpClient client = new SmtpClient(sSMTPServer);
>
> try
>
> {
>
> client.Credentials = CredentialCache.DefaultNetworkCredentials;
>
> }
>
> catch (Exception excpt)
>
> {
>
> Console.WriteLine("An error occurred initialising the mail client. " +
> excpt.Message + "\n");
>
> }
>
> try
>
> {
>
> client.Send(message);
>
> }
>
> catch (Exception excpt)
>
> {
>
> Console.WriteLine("An error occurred sending the mail. " + excpt.Message +
> "\n");
>
> }
>
> }
>
> else
>
> {
>
> Console.WriteLine("Parameter error." + "\n");
>
> ShowParameters();
>
> }
>
> }
>
> else
>
> {
>
> ShowParameters();
>
> }
>
> }
>
> catch (Exception excpt)
>
> {
>
> Console.WriteLine("A horrible error occurred. " + excpt.Message + "\n");
>
> }
>
> }
>
> private static void ShowParameters()
>
> {
>
> Console.WriteLine("SMTP - Version 1.0");
>
> Console.WriteLine("USAGE:");
>
> Console.WriteLine("smtp [From Email Address] | [To Email Address] |
> [Subject] | [Body Text] | [Attachment Filename]");
>
> }
>
> }
>
>
> Request for the permission of type 'System.Net.Mail.S
> mtpPermission, System, Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c56
> 1934e089' failed.
>
>

AddThis Social Bookmark Button