2016-09-19 4 views
0

에서 클래스 라이브러리에서 Resources.resw를 사용하는 방법 "을위한 ResourceLoader RL = ResourceLoader.GetForCurrentView ("으로 ClassLibrary1/자료 ");" UWP - 라이브러리</p> <pre><code> public string GetName() { ResourceLoader rl = ResourceLoader.GetForCurrentView("ClassLibrary1/Resources"); return rl.GetString("Name"); } </code></pre> <p>에서

가 'System.Runtime.InteropServices.COMException'형식의 예외가 발생하지만, 한 ClassLibrary1.dll 사용자 코드에 처리되지

WinRT 정보 : 未 找到 ResourceMap

추가 정보 :. 未 找到 ResourceMap .

未 找到 ResourceMap.

이 예외 핸들러가있는 경우, 프로그램은 안전하게 계속 될 수있다.

이 라이브러리를 참조하도록 추가하면 올바르게 작동합니다. 하지만 동적으로이 라이브러리를 참조하면 실패합니다.

 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 

어떻게 라이브러리에 동적 참조를 위해 자원을 사용 하는가?

답변

0

이 라이브러리를 참조하도록 추가하면 잘 작동합니다. 하지만 난이 라이브러리를 동적 참조, 그것은 실패입니다.

코드의 대부분이 옳았는데 정확히 예외가 무엇인지 언급하지 않았습니다.

휴대용 클래스 라이브러리, 클래스 1 :

public class Class1 
{ 
    public Class1() 
    { 
     Debug.WriteLine("ClassLib Loaded!"); 
    } 

    public void Output() 
    { 
     Debug.WriteLine("ClassLib method!"); 
    } 
} 

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); 

직접 실행 창에 출력은 다음과 같이이다 :

enter image description here

이렇게하려면 이 필요합니다. :

  1. 클래스 라이브러리를 빌드하십시오.

:

  • 바로이처럼 UWP 프로젝트에 ClassLibrary1.dll를 복사 "빈"폴더 => "디버그"를 찾아 폴더에, "파일 탐색기에서 폴더 열기"를 선택 클래스 lib 디렉토리를 클릭

    enter image description here

    이렇게하면 문제를 해결할 수 있지만 ,하지만 내 개인적인 의견으로는, 그것은 바로이 라이브러리의 참조를 추가보다 쉽게 ​​보인다.

  • +0

    답장을 주셔서 감사합니다. – wangji

    +0

    @wangji,이 답변입니까? 그렇다면이 대답을 표시해 주시겠습니까? –

    +0

    답변 해 주셔서 감사합니다. 동적 참조 유형을 사용하여 ".dll"을로드하고 사용하고 싶습니다.dll "응용 프로그램이 동적 인".dll "을 추가 할 것이므로 – wangji