Question Web site Pubishing

azure

New member
Joined
Mar 21, 2009
Messages
4
Programming Experience
1-3
Hi All,

I was using C# before I moved to my new job. Now I am using vb.net.
I face a problem whenever I publish my asp.net website.
I have many pages that consumed an assembly(business object). And I add a new optional parameter to the method in this assembly class.
When I publish the website, it's working fine on local PC.
But when I update this assembly without updating the pages that consumed it to the server, I got an error message like, cannot find the method name.
I never got this error in C# before.

Please enlighten me.

Thanks
 
Cannot fine the method name

Hi All,

I was using C# before I moved to my new job. Now I am using vb.net.
I face a problem whenever I publish my asp.net website.
I have many pages that consumed an assembly(business object). And I add a new optional parameter to the method in this assembly class.
When I publish the website, it's working fine on local PC.
But when I update this assembly without updating the pages that consumed it to the server, I got an error message like, cannot find the method name.
I never got this error in C# before.

Please enlighten me.

Thanks

Unfortunately i am unable to reproduce the issue with the steps you provided. I changed some method names and then i ran some pages that do not use these methods so it worked just fine.

Please post exact steps that might help me reproduce the issue. Thanks
 
The sample

Here's an example.
I've two projects. One is the dll project and the other Console Application.
In the dll project:
***********************************
namespace DLL

public class TestClass​
public Function GetSomeString() as String​
Dim retStr as String = "Test String"​
return retStr​
End Function​
end class​
end namespace

**********************************
And here in the Console Application Project:

Module Module1
Sub Main()​
Dim str = New TestClass().GetSomeString()​
Console.WriteLine(str)​
Console.ReadLine()​
End Sub​
End Module

I add the dll project as the reference for this Console Application. And it's work fine.
**********************************************

But when I change the Dll Project as the following and only compile the dll project and then copy the output assembly to the Console Application's bin folder without recompiling the Console Application project, I got the error. But in C# I never got this error. I do it in C# with method overloading.

The modified code for the Dll project is:

************************
namespace DLL

public class TestClass​
public Function GetSomeString(Optional ByVal param as String = "hello") as String​
Dim retStr as String = "Test String"​
return retStr​
End Function​
end class​
end namespace
****************************


And the error I got is something like : "The method name GetSomeString() cannot be found"
 
You can't do this, not with method overloading and not with Optional parameters, because the method signature you are calling is removed. It would be the same the opposite direction, if you had the Optional version and removed the paramter, the console calling the method could no longer find a method with a (optional) string parameter. So, even if the parameter value is optional the method signature is not.
 
Hello,


Ok i see what you mean now!

You seem to be missing an important thing about the optional parameters in VB.NET.

As you know in VB.NET you have possibility of making method parameters Optional. This means you can omit these parameters when calling the method. However optional parameters must specify a default value.

VB.NET:
Public Function GetSomeString(Optional ByVal param as String [COLOR=Red]= [B]""[/B][/COLOR]) as String
    Dim retStr as String = "Test String"
    return retStr
End Function

As per the C#; C# doesn't support optional parameters and forces you to use overloading.

Actually when the compiler implements optional parameters, it's actually writing the overloaded functions for you so you end up with the same.

Means just specify default value for the optional parameter and you'll be fine.
 
azure means changing the dll method signature without recompiling the caller/consumer app. This can only be done by adding signatures, not removing an existing signature that is already called by consumer.
kulrom said:
Actually when the compiler implements optional parameters, it's actually writing the overloaded functions for you so you end up with the same.
No, it just puts the default value in the call if it is not provided. It still calls the method(string) signature.
 
Hi John,

Well i believe that a function with an optional parameter is in reality two different functions.

One that assumes some default behavior if the optional parameter is omitted, and another that performs more specific behavior based on the value of the optional parameter if provided.

So when the compiler implements optional parameters, it's actually writing the overloaded functions for you.

Ok maybe i have misunderstood how it works ! Thanks for the clarification.


 
kulrom said:
Well i believe that a function with an optional parameter is in reality two different functions.
Only functionally at design time.
So when the compiler implements optional parameters, it's actually writing the overloaded functions for you.
No, it doesn't. The compiler inserts the default value in the call if it is not supplied. See this example that examines the IL code: cesarafonso: VB.NET Optional parameters
You can also inspect the methods available from library at runtime with Reflection, where there are optional parameters there is still only one method.
 
I know, but if it was not metaphorically and compiler actually had generated all the overloaded methods for optional parameters then OP wouldn't be having this problem because the parameterless method would have remained available.
 
Hi John and kulrom,
Thanks for your answer!

So what I understand now is I need to recompile all the client class that use this assembly, if the method signature in this assembly is changing, Right?
 
Well, if you're removing a method signature that existing clients rely on then that is your only option.
 

Latest posts

Back
Top