简体   繁体   中英

How can I load assemblies that are placed in the project (portable class library) folder?

I have a .dll file in my project folder and would like to load it via Assembly.Load().

AssemblyName name = new AssemblyName("Portable.Store, Version=0.1.0.0, Culture=neutral, PublicKeyToken=12ay62c33eocf6uf");
Assembly assembly = Assembly.Load(name);

However this would throw a FileNotFoundException due to not specifying a path. And I am unable to use Assembly.LoadFrom() or Assembly.LoadFile() because Portable Class Libraries only support Assembly.Load()

Is there a way to do this inside a pcl? Any help is appreciated, thank you!

Edit #1 : Would it matter if the assembly I'm trying to load is a non PCL? I know that this defeats the purpose of the PCL however there are a few libraries that are not included in the PCL. Therefore using conditional compilation, depending on the platform, I will load platform specific assemblies.

Edit #2 : Found some more information on where the dll should be placed: https://stackoverflow.com/a/6440406/2464165

As of now I just placed it inside my project folder, with the .sln file and what not Where exactly would be the app probing path?

Edit #3 : I was able to get my dll file placed inside the Resources Folder of a .dll file. So I have MyPCL.dll and inside that is where I have the ResourcesFolder/Portable.Store. How could I tell the Assembly.Load to look in specific folders instead of just the main AppX root directory?

I'm making the assumption that you are running the portable library in a Windows Store application (based on the assembly name you are trying to load).

There are two places that store apps find their assemblies, either in GAC if it is a framework assembly or the Appx package if it is a user assembly.

As "Portable.Store" (which I assuming is from my PclContrib project) is a user assembly, it must be loaded from the AppX package. To ensure that both assemblies end up in the AppX package, simply make sure that the Windows Store project containing the AppxManifest references both of them. That's it.

If Assembly.Load still cannot find the assembly, check to make sure that the strong name you are passing to Assembly.Load is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM