From: ray on
Hi All,

I have a DLL created by VB.net with the following function:

Public Shared Function Upload(ByRef thePage As Page) As String

I have no problem calling from a VB.net ASPX page, but having problem
with C# page with the following call:

protected void Page_Init(object sender, EventArgs e)
{
string msg = "";
msg = UploadLIB.Upload(ref Page);
}

Compiler Error Message: CS0206: A property or indexer may not be passed
as an out or ref parameter

Thanks for help.

Ray


From: Alberto Poblacion on
"ray" <ray(a)newsgroup.com> wrote in message
news:MPG.265712fa45c65b3c989682(a)news.microsoft.com...
> I have a DLL created by VB.net with the following function:
>
> Public Shared Function Upload(ByRef thePage As Page) As String
>
> I have no problem calling from a VB.net ASPX page, but having problem
> with C# page with the following call:
>
> protected void Page_Init(object sender, EventArgs e)
> {
> string msg = "";
> msg = UploadLIB.Upload(ref Page);
> }
>
> Compiler Error Message: CS0206: A property or indexer may not be passed
> as an out or ref parameter

You cannot pass a property as a reference. You will need to copy it to a
variable to satisfy the compiler:

System.Web.UI.Page thePage = this.Page;
msg = UploadLIB.Upload(ref thePage);

However, passing the page by reference is quite unusual. It is already a
reference-type, so you are actually passing a reference to the reference.
This is unnecessary unless you intend to change the reference itself so that
it points to a new object, which is not something that you would do with the
page that is processing the request. If you analyze and reconsider what you
are doing, you will probably find that the method can be rewritten to take a
ByVal parameter.


 | 
Pages: 1
Prev: IComparer
Next: Report Viewer Memory Leak