请帮我解决这个错误:不能类型的对象隐式转换为System.Reflection.Assembly
Cannot implicitly convert type 'object' to 'System.Reflection.Assembly'. An explicit conversion exists (are you missing a cast?)
谢谢!
CODE
var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
var ads = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
DisallowCodeDownload = true
};
AppDomain newDomainName = AppDomain.CreateDomain("newDomainName", null, ads);
Assembly testLibrary = newDomainName.CreateInstanceAndUnwrap(assemblyName.Name,
typeof(System.Windows.Controls.UserControl).Name); // Here the error occures
尝试更正圆括号匹配typeof(System.Windows.Controls.UserControl).Name)您缺少开头paranthesis EX:typeof((System.Windows.Controls.UserControl).Name) – Freeman
@Freeman不,圆括号是正确的。第一个右括号属于'typeof',第二个是'CreateInstanceAndUnwrap'的右括号。 – hvd
我不明白你想要做什么。你似乎是在一个新的域中创建一个'UserControl',然后将它存储在'Assembly'类型的变量中。这对我来说没有意义。编辑:除此之外,你没有传递包含'UserControl'类型的程序集的程序集名称,所以它不会起作用。 – hvd