So I created this dll file, and i am trying to call the methods dynamically
namespace getDirInf {
public static class fileInf
{
public static long FileSizeRecursive(string strDirectory, long p_lnDirLength)
{
DirectoryInfo _dinf = new DirectoryInfo(strDirectory);
DirectoryInfo[] _dirs = _dinf.GetDirectories();
long _lnDirSize = p_lnDirLength;
_lnDirSize += GetFileSize(strDirectory);
if (_dirs.Length == 0)
{
return _lnDirSize;
}
else
{
foreach (DirectoryInfo dir in _dirs)
{
_lnDirSize = FileSizeRecursive(dir.FullName, _lnDirSize);
}
return _lnDirSize;
}
}
public static long GetFileSize(string strDirectory)
{
long _lnDirSize = 0;
DirectoryInfo _dinf = new DirectoryInfo(strDirectory);
FileInfo[] dirFiles = _dinf.GetFiles();
foreach (FileInfo fi in dirFiles)
{
_lnDirSize += fi.Length;
}
return _lnDirSize;
}
}
}
And thats the function i'm using to call the methods in dll, this is the constructor
public ThreadCall(string _path, TextBox txtSize)
{
this._path = _path;
this.txtSize = txtSize;
Assembly assembly = Assembly.LoadFile("C:\\...\\getDirInf.dll");
var type = assembly.GetType("getDirInf.fileInf");
MethodInfo method = type.GetMethod("FileSizeRecursive", BindingFlags.Public | BindingFlags.Static);
}
And this is the function call.
public void callThread()
{
k = method.Invoke(null, new object[] { _path, 0L }); //this is where i'm having problems
}
Since the methods in dll are all static, i am trying to call method.Invoke with null as first parameter, and as second the parameters of function. I thought when the method is static, you don't need an instance in invoke and it would work with null but now i'm having null reference exception with this code...
Any help about how to solve this would be appreciated, thanks.