0
マイコード:Assembly.GetType( "[...]"、true);スローTypeLoadException
//App, Core.cs
using System;
using System.IO;
using System.Reflection;
namespace Game
{
public static void Main(string[] args)
{
Assembly a = Assembly.LoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mods\\ExampleMod.dll"));
var x1 = a.GetType("PTF_Mod.Mod_Main");
var x2 = x1.GetMethod("OnStart");
var x3 = x2.Invoke(null, new object[] { });
while(true);
}
}
//App, ModCrew.cs
using System;
using System.Reflection;
namespace Engine
{
public static class ModCrew
{
public class Mod
{
public void ItWorks()
{
Console.WriteLine("It works!");
}
}
}
}
//DLL, Mod_Main.cs
using System;
using System.Reflection;
namespace PTF_Mod
{
public static class Mod_Main
{
public static void OnStart()
{
var exe = Assembly.GetCallingAssembly();
Console.WriteLine(exe.Location); //Location is valid
var x = exe.GetType("Engine.ModCrew.Mod", true); //But here I get exception
var y = Activator.CreateInstance(x);
x.GetMethod("ItWorks", BindingFlags.Instance).Invoke(null, object[] { });
}
}
}
例外:型 'System.TypeLoadException' の例外ががmscorlib.dllで発生したが、ユーザーコードで処理されなかった
追加情報:NIEのmożnazaładowaćtypu " Engine.ModCrew.Mod 'z zestawu'ゲーム、バージョン= 0.0.0.0、文化=ニュートラル、PublicKeyToken = null '。
「Engine.ModCrew + Mod」「 – PetSerAl
」次にTypeLoadExceptionを「var x3 = x2.Invoke(null、new object [ {}); " in Core.cs – TheChilliPL
"mscorlib.dllで 'System.TypeLoadException'の例外が発生しましたが、ユーザーコード" – TheChilliPL