A
Andy
Hi, how do you allow strongly type cast parameters to be passed to C#
functions that use weakly type cast parameters while running under the
"Medium" Trust Level security policy shipped with the ASP.NET 1.1
framework?
I've written a general error reporting routine that formats and returns
error messages for various exceptions. The routine accepts a
System.Object which it then typecasts into the correct exception object
using the object's name property.
When I run this under the "Full" Trust Level security policy, the
routine works and no errors are reported.
When I run this under the "Medium" Trust Level security policy on our
shared webhosting provider, the routine fails to compile because the
..NET code verifier flags all the calls to this error routine as
"unsafe", because the data types of the expected and passed parameters
do not match.
The actual error reported is "System.Security.VerificationException:
Operation could destabilize the runtime". The problem line in the
stack trace points to the function definition line for rptError that
contains the expected System.Object parameter.
The shared webhosting provider has not modified the "Medium" Trust
Level security policy, and has used it "as-is" from the .NET 1.1
framework.
Sample code of the call and function appears below:
try{
... arbitrary code that may throw an exception ...
}catch (Exception e){
result = rptError((System.Object) e);
}
public System.String rptError(System.Object objError)
{
string result="";
switch(objError.GetType().Name)
{
case "Exception":
Exception e=(FormatException)objError;
result = "exception: " + Environment.NewLine +
e.Message + Environment.NewLine +
e.Source + Environment.NewLine +
e.StackTrace;
break;
}
return(result);
}
Can anyone see what is going wrong here?
Andy
functions that use weakly type cast parameters while running under the
"Medium" Trust Level security policy shipped with the ASP.NET 1.1
framework?
I've written a general error reporting routine that formats and returns
error messages for various exceptions. The routine accepts a
System.Object which it then typecasts into the correct exception object
using the object's name property.
When I run this under the "Full" Trust Level security policy, the
routine works and no errors are reported.
When I run this under the "Medium" Trust Level security policy on our
shared webhosting provider, the routine fails to compile because the
..NET code verifier flags all the calls to this error routine as
"unsafe", because the data types of the expected and passed parameters
do not match.
The actual error reported is "System.Security.VerificationException:
Operation could destabilize the runtime". The problem line in the
stack trace points to the function definition line for rptError that
contains the expected System.Object parameter.
The shared webhosting provider has not modified the "Medium" Trust
Level security policy, and has used it "as-is" from the .NET 1.1
framework.
Sample code of the call and function appears below:
try{
... arbitrary code that may throw an exception ...
}catch (Exception e){
result = rptError((System.Object) e);
}
public System.String rptError(System.Object objError)
{
string result="";
switch(objError.GetType().Name)
{
case "Exception":
Exception e=(FormatException)objError;
result = "exception: " + Environment.NewLine +
e.Message + Environment.NewLine +
e.Source + Environment.NewLine +
e.StackTrace;
break;
}
return(result);
}
Can anyone see what is going wrong here?
Andy