0
I’m calling the following function put it gives this problem "Parameter count error" when executing:
url = (string)miScriptReference_GetUrl.Invoke(this, new object[] { scriptManager, value, false });
Code:
public string GetUrl(ScriptManager scriptManager)
{
string url = string.Empty;
if (String.IsNullOrEmpty(Path))
{
try
{
PropertyInfo piScriptManager_IControl = scriptManager.GetType().GetProperty("Control", BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo miScriptReference_GetUrl = typeof(ScriptReference).GetMethod("GetUrl", BindingFlags.NonPublic | BindingFlags.Instance);
Type typeIControl = Type.GetType(piScriptManager_IControl.PropertyType.AssemblyQualifiedName.ToString(), false, true);
//object value = Convert.ChangeType(piScriptManager_IControl.PropertyType, typeIControl);
object value = piScriptManager_IControl.GetValue(scriptManager, null);
url = (string)miScriptReference_GetUrl.Invoke(this, new object[] { scriptManager, value, false });
/*return base.GetUrl(scriptManager, false); //Ajax 3.5*/
//MethodInfo miGetScriptResourceUrl = typeof(ScriptManager).GetMethod("GetScriptResourceUrl", BindingFlags.NonPublic | BindingFlags.Instance);
//Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
//url = (string)miGetScriptResourceUrl.Invoke(scriptManager, new object[] { Name, asm });
}
catch (Exception ex)
{
throw ex;
}
}
else
{
url = scriptManager.ResolveClientUrl(Path);
}
return url;
}
This problem started after migrating vs from . net from 2.0 to 4.7
I saw nothing of the mistake itself because in the form presented it did not motivate me to see, but if you take this
try-catch
It already helps your code get better, because it does nothing but spoil the stack trace*. Never use something you don’t know what it’s for and what you’re doing. This will help you more with your current mistake and all the others that will come. But I see a lot of really bad things in this code, I think it can be much simpler and probably wouldn’t even have that mistake.– Maniero
Since you say it could be simpler, please show me in the answer a simpler way and help me solve... ps: I am migrating this code must be about 10 years old!
– Gabriel Souza