나는 두 개의 외부 DLL을 사용합니다 간단한 WPF 응용 프로그램을하고 있어요 Nancy.dll
및 Nancy.Hosting.Self.dll
HTTP를 통해 일부 데이터를 보낼 수 있습니다. .exe 파일을 독립 실행 형으로 유지하고 싶으므로 두 개의 .dll 파일을 응용 프로그램에 병합하려고합니다. 나는 다음과 같은 방법을 병합 여러 빌드 후 시도 NetZ
와 ILMerge
,하지만 모두 WPF 응용 프로그램에 문제가있는 것 같습니다 및 출력 작업 실행하지 않았다.
이 게시물 이 문제에 대해 진행에 대한 여러 제안이 같은 두 가지로 그들은 비록 모든 종기 아래 :
AppDomain.CurrentDomain.AssemblyResolve
필요한 경우 이벤트를 사용 하여로드합니다.두 번째 옵션은 유망 해 보였습니다. 이벤트가 트리거되고, 포함 된 리소스를 찾고, 데이터 스트림을 만들어 어셈블리로로드합니다. 어셈블리가 여러 방법으로로드되었는지 확인할 수 있습니다.
Visual Studio Debug -> Windows -> Modules
는로드 된 어셈블리를 표시하고로드되는 어셈블리
AppDomain.CurrentDomain.GetAssemblies()
도 표시합니다.
그러나 어셈블리를 사용할 때 (이 경우를 호출 Nancy.Hosting.Self.NancyHost host = new NancyHost();
) 여전히 다음 오류가 발생합니다.
Could not load file or assembly 'Nancy, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
여기에 제안 된대로 모든 종속성도로드 되고로드 된 모든 어셈블리가 동일한 AppDomain에 있는지 확인했습니다 . 또한 위의 오류는에만 해당 Nancy.dll
되며 AssemblyResolve
이벤트가 Nancy.Hosting.Self.dll
올바르게 로드 됩니다.
난 정말 내가 잘못 일을 할 수있는 다른 무엇을 볼 수 없습니다, 그리고 뭔가 나 어셈블리를로드할지 여부를 특별히 이상하게 작동한다 낸시입니다으로 잘못 여부 (I 발견 GitHub의에서이 문제를 내가가 관련이 있는지 여부 불확실 해요있는) . 어셈블리로드, dll 병합 또는 Nancy의 대안에 대한 제안이 있다면 매우 기쁩니다.
추신 :
에서 다른 메서드를 호출하려고했는데 Nancy.dll
놀랍게도 할 수있었습니다. 이 AssemblyResolve
방법은 실제로 작동합니다.
초기화 Nancy.Hosting.Self.NancyHost
는 여전히 문제가 있으며 스택 추적은 그 이유를 알려줍니다.
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at Nancy.AppDomainAssemblyCatalog.CreateRemoteReferenceProber(AppDomain appDomain)
at Nancy.AppDomainAssemblyCatalog.LoadNancyReferencingAssemblies(IEnumerable`1 loadedAssemblies)
at Nancy.AppDomainAssemblyCatalog.GetAvailableAssemblies()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Nancy.DefaultTypeCatalog.GetTypesAssignableTo(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Nancy.DefaultTypeCatalog.GetTypesAssignableTo(Type type, TypeResolveStrategy strategy)
at Nancy.Bootstrapper.NancyBootstrapperLocator.GetBootstrapperType(ITypeCatalog typeCatalog)
at Nancy.Bootstrapper.NancyBootstrapperLocator.LocateBootstrapper()
at Nancy.Bootstrapper.NancyBootstrapperLocator.get_Bootstrapper()
따라서 Nancy는 부트 스트 래퍼를 초기화 할 때 참조 어셈블리를 가져 오려고 시도 하고이를 위해 GetAssemblyDirectories 메서드를 사용합니다 . 당연히 DLL은 거기에 존재하지 않으며 (.exe로 병합하려고 할 때) 부트 스트 래퍼가 초기화에 실패합니다.
이 문제를 고칠 수없고 Nancy는 더 이상 유지 관리되지 않으므로 내 질문을 다시 말하고 싶습니다.
C #을위한 멋진 경량 웹 프레임 워크를 아는 사람이 있습니까?
나는 Nancy
그냥 나를 위해 잘 작동하기 때문에 다른 것을 찾아보고 싶지 않았습니다 . 대신 내가 낸 것은 nancy가 그것을 찾고, 부트 스트 래퍼를 초기화하고, 데이터를 다시 제거 할 것이라는 것을 알고있는 곳에 dll을 작성하는 것이 었습니다.
bool NancyPresent = File.Exists("Nancy.dll");
if (!NancyPresent) {
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("Resources.Nancy.dll"))
using (MemoryStream MS = new MemoryStream()) {
stream.CopyTo(MS);
File.WriteAllBytes("Nancy.dll", MS.ToArray());
}
Nancy.Bootstrapper.INancyBootstrapper bootstrapper = Nancy.Bootstrapper.NancyBootstrapperLocator.Bootstrapper;
bootstrapper.Initialise();
File.Delete("Nancy.dll");
}
테이크 아웃 메시지는 Nancy의 오류가 달리 표시 했음에도 불구하고 dll이 제대로로드되고 있다는 것입니다. 오픈 소스라 할지라도 써드 파티 패키지가 정확히 무엇을할지 알 수 없습니다!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다