[英]UWP - How to use Resources.resw in class library
in library 在图书馆
public string GetName()
{
ResourceLoader rl = ResourceLoader.GetForCurrentView("ClassLibrary1/Resources");
return rl.GetString("Name");
}
at "ResourceLoader rl = ResourceLoader.GetForCurrentView("ClassLibrary1/Resources");" 在“ ResourceLoader rl = ResourceLoader.GetForCurrentView(“ ClassLibrary1 / Resources”);“
An exception of type 'System.Runtime.InteropServices.COMException' occurred in ClassLibrary1.dll but was not handled in user code ClassLibrary1.dll中发生类型'System.Runtime.InteropServices.COMException'的异常,但未在用户代码中处理
WinRT information: 未找到 ResourceMap。 WinRT信息:未找到ResourceMap。
Additional information: 未找到 ResourceMap。 附加信息:未找到ResourceMap。
未找到 ResourceMap。 未找到ResourceMap。
If there is a handler for this exception, the program may be safely continued. 如果有用于此异常的处理程序,则可以安全地继续执行该程序。
if i add reference this library , it is working well. 如果我添加参考此库,它运行良好。 but i Dynamic reference this library ,it is failure. 但是我动态引用了这个库,这是失败的。
Assembly assembly = Assembly.Load(new AssemblyName("ClassLibrary1"));
if (assembly == null)
{
return;
}
Type type = assembly.GetType("ClassLibrary1.Class1");
ICore core = Activator.CreateInstance(type) as ICore;
textBlock1.Text = core.GetName();
//ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1();
//textBlock1.Text = c1.GetName(); //it is working well
how to use resources for Dynamic reference in the library? 如何在库中使用资源进行动态引用?
if i add reference this library , it is working well. 如果我添加参考此库,它运行良好。 but i Dynamic reference this library ,it is failure. 但是我动态引用了这个库,这是失败的。
Most of your code is right, you didn't mention what exactly the exception is. 您的大多数代码是正确的,您没有提到确切的异常是什么。 Here is my demo: 这是我的演示:
Portable class library, class1: 便携式类库,class1:
public class Class1
{
public Class1()
{
Debug.WriteLine("ClassLib Loaded!");
}
public void Output()
{
Debug.WriteLine("ClassLib method!");
}
}
In UWP app: 在UWP应用中:
Assembly assembly = Assembly.Load(new AssemblyName("ClassLibrary1"));
if (assembly == null)
{
return;
}
Type type = assembly.GetType("ClassLibrary1.Class1");
object obj = Activator.CreateInstance(type);
var method = type.GetMethod("Output");
method.Invoke(obj, null);
The output in the immediate window is like this: 立即窗口中的输出如下所示:
To do this, you will need to : 为此,您将需要 :
build your class library. 建立您的课程库。
right click your class lib, choose "Open folder in File Explorer", in the folder find the "bin" folder => "Debug", copy the ClassLibrary1.dll
into your UWP project like this: 右键单击您的类库,选择“在文件资源管理器中打开文件夹”,在该文件夹中找到“ bin”文件夹=>“调试”,将ClassLibrary1.dll
复制到您的UWP项目中,如下所示:
Although doing this can solve the problem, but in my personal opinion, it seems not easier than directly adding reference of this library. 尽管这样做可以解决问题,但是在我个人看来,这似乎比直接添加该库的引用要容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.