[英]Get Type from Fully qualified name only in Windows Store App
I have a string containing a full qualified name like MyNamespace.MyType
which I know is in a loaded assembly. 我有一个包含完整合格名称的字符串,例如
MyNamespace.MyType
,我知道它在已加载的程序集中。
I need to get the Type
instance of this, in a windows store app. 我需要在Windows应用商店中获取
Type
实例。
The issue I'm having is that while there is some reflection classes in windows store apps, it's very limited, and I simply can't use what I've been using for a desktop app. 我遇到的问题是,尽管Windows应用商店中有一些反射类,但是它非常有限,而且我根本无法使用桌面应用中一直使用的东西。
If I can get an assembly I can find my type within it so I'm currently trying to get all loaded assemblies, which I can't do easily as AppDomain
doesn't exist. 如果可以获取程序集,则可以在其中找到我的类型,因此我目前正在尝试获取所有已加载的程序集,由于
AppDomain
不存在,因此我不容易做到。
I found the following: 我发现以下内容:
private async System.Threading.Tasks.Task<IEnumerable<Assembly>> GetAssembliesCore()
{
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
List<Assembly> assemblies = new List<Assembly>();
foreach (Windows.Storage.StorageFile file in
await folder.GetFilesAsync().AsTask().ConfigureAwait(false))
{
if (file.FileType == ".dll")
{
AssemblyName name = new AssemblyName() { Name = file.Name };
Assembly asm = Assembly.Load(name);
assemblies.Add(asm);
}
}
return assemblies;
}
I added the .AsTask().ConfigureAwait(false)
to stop it hanging, but it now fails trying to load the assembly: 我添加了
.AsTask().ConfigureAwait(false)
以使其停止挂起,但现在尝试加载程序集失败:
"Could not load file or assembly 'FDE.Audio.dll' or one of its dependencies.
“无法加载文件或程序集'FDE.Audio.dll'或其依赖项之一。
The system cannot find the file specified.":"FDE.Audio.dll"系统找不到指定的文件。“:”“ FDE.Audio.dll”
Is there something I need to set up in the manifest? 清单中是否需要设置某些内容? Something else?
还有吗
How can I load an assembly in my program's folder ( AppX
I think)? 如何在程序的文件夹(我认为是
AppX
)中加载程序集?
Try to extract file name without extension 尝试提取不带扩展名的文件名
var filename = file.Name.Substring(0, file.Name.Length - file.FileType.Length);
AssemblyName name = new AssemblyName() { Name = filename };
Assembly asm = Assembly.Load(name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.