Witam!
Piszę obecnie mały "system operacyjny" w exe-ku i natknąłem się na problem z wtyczkami.
Wtyczki ładuję w ten sposób:
public void loadKernel()
{
bool ok = false;
Assembly asm = Assembly.LoadFrom(kernelFile);
foreach (Type type in asm.GetTypes())
{
if (type.IsPublic && !type.IsAbstract)
{
Type iFace = type.GetInterface("system.sys.IKernel", true);
if (iFace != null)
{
IKernel tmp = (IKernel)Activator.CreateInstance(asm.GetType(type.ToString())); //Ta linia zwraca błąd
tmp.pHost = this;
kernel = tmp;
kernel.pHost = this;
kernel.Load();
ok = true;
}
iFace = null;
}
}
if (!ok) throw new Exception();
}
kod mojej wtyczki:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace system.sys
{
public class kernel : IKernel
{
class zdriver
{
public string path;
public string name;
public zdriver(string Path, string Name)
{
path = Path;
name = Name;
}
}
public IPlugHost pHost
{
get
{
return Host;
}
set
{
Host = value;
}
}
IPlugHost Host;
public string Name { get { return "kernel"; } }
public string Version { get { return "1.0"; } }
public string Author { get { return "Bartosz Grabias"; } }
public string Description { get { return ""; } }
List<zdriver> drivers = new List<zdriver>();
public kernel()
{
drivers.Add(new zdriver(pHost.SysDir+@"\lowlevel\keyboard.bsys", "keyboard"));
drivers.Add(new zdriver(pHost.SysDir + @"\normallevel\ExtendedFileSystem.bin", "keyboard"));
}
void writeError()
{
Console.Write("[");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ERROR");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("]");
}
void writeok()
{
Console.Write("[");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(" OK ");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("]");
}
public void Load()
{
writeok();
foreach (zdriver a in drivers)
{
}
}
void write(string text)
{
Console.Write(text);
for (int a = 37; a >= 37 - text.Length; a--)
{
Console.Write(" ");
}
}
}
}
oraz kod interface-ów:
public interface IKernel
{
IPlugHost pHost { get; set; }
string Name { get; }
string Version { get; }
string Author { get; }
string Description { get; }
void Load();
}
public interface IPlugHost
{
Version version { get; }
string UserDir { get; }
string SysDir { get; }
string MainDir { get; }
bool CheckFileExist(string File);
bool CreateFile(string File);
bool DeleteFile(string File);
string ReadFile(string File);
bool WriteFile(string File, string Text);
}
Zwraca ny błąd brzmi "Exception has been thrown by the target of an invocation."
Proszę o szybką odpowiedź
Z poważaniem Bartek