Я пытаюсь сделать приложение, которое сообщает мне общее время всех видеороликов. Его не практично это только практика, чтобы улучшить мои кодирования способности :)«InvalidCastException был необработанным»
В этой строке будет ошибка
Shell32.Shell shell = new Shell32.Shell();
И это ошибка
Unable to cast COM object of type 'System .__ ComObject' to interface type 'Shell32.Shell'. There was an error in operation because the QueryInterface call on the COM component for the interface with IID '{} 286E6F1B-7113-4355-9562-96B7E9D64C54' generated the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Shell32;
namespace cuentavideosconsola
{
class Program
{
static void Main(string[] args)
{
double contartiempo = 0;
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder carpeta;
carpeta = shell.NameSpace(@"D:\");
foreach(Shell32.FolderItem2 item in carpeta.Items()){
Console.WriteLine(carpeta.GetDetailsOf(item,27));
TimeSpan tiempo = TimeSpan.Parse(carpeta.GetDetailsOf(item,27));
contartiempo += tiempo.TotalSeconds;
}
Console.WriteLine("El total de tiempo de los videos es: " + contartiempo);
Console.ReadLine();
}
}
}
Ну, я думаю, не все люди могут понять ошибку, о которой вы упомянули. – sdeep
В большинстве случаев перед сообщением есть код ошибки. Это очень поможет, поскольку оно не зависит от языка. –
Visual studio помещает ошибку здесь Shell32.Shell shell = new Shell32.Shell(); –