I am adding Optional Parameter in My ClassLibrary
Example
public static string GetData(string name, string surname, bool status = false){}
And My ASPX page is calling method
GetData(string name, string surname)
I just rebuilt ClassLibrary And Not the ASP page. Then It threw error Method Not Found
Please help how to maintain backward compatibility? means if i replce just classlibrary then it should not affect my ASP page. I ma using .NET version 4
Thank you
If you really want binary compatibility then yes, you can't add even an optional parameter. What you can do is add an overload:
Before:
public static string GetData(string name, string surname)
{
// Real code
}
After:
public static string GetData(string name, string surname)
{
return GetData(name, surname, false);
}
public static string GetData(string name, string surname, bool status)
{
// Real code
}
Note that you could make status
optional, but there wouldn't be much point, as any callers not providing an argument would end up calling the two-parameter version. If you were adding more than one parameter though, it would make more sense.
You may well want to consider whether you could live with "rebuilding compatibility", i.e. "all is okay if I rebuild". Strict backward compatibility can be very restrictive - these days just dropping a new binary into a built application is relatively rare compared with picking up a new package version when building.
See more on this question at Stackoverflow