1

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?

Community
  • 1
  • 1
KrispyDonuts
  • 1,262
  • 2
  • 18
  • 37
  • 1
    It seems like you use the Assembly Name Ctor at the wrong way. Take a look into [this](http://msdn.microsoft.com/en-us/library/b6ccxba0.aspx) Example. You must use a full name like `mylib, Version=1.2.1900.0, Culture=neutral, PublicKeyToken=a14f3033def15840` – Venson Aug 14 '13 at 18:27
  • By your project folder do you mean the same folder the application is located in? – Chris Aug 14 '13 at 18:32
  • @Venson I have updated my post above with what you stated. Unfortunately this would still cause the same error. – KrispyDonuts Aug 14 '13 at 18:35
  • @Chris Yes, it is in the same folder that the application is in. – KrispyDonuts Aug 14 '13 at 18:35
  • it needs to be located in the same folder as the binary (probably your \bin folder). – Chris Aug 14 '13 at 19:00
  • That did the trick. I had to place the dll inside my [ApplicationFolder]/bin/Debug/AppX and not inside the PCL project bin folder. Thanks Chris! Now it seems like this would be a temporary fix. Because if I had to package up this PCL and hand it off to some other developer, would he have to manually place it inside his own Application's bin folder? Or would there be a way to somehow tell the application to look for the dll inside the PCL? – KrispyDonuts Aug 14 '13 at 19:09
  • Actually, just found out that if i just placed it inside the AppX folder, I wouldn't need to call Assembly.Load at all. It seems that this might not be what I was looking for because I would be manually placing the file inside the install directory. – KrispyDonuts Aug 14 '13 at 19:13
  • @Ryan.dn Give this a read. It outlines how the runtime goes about loading assemblies http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx – Chris Aug 14 '13 at 19:34
  • @Chris Thanks again, am still looking through the link you sent me but it seems like most of this is looking in the application root installation directory. This is during runtime so the dll would have to exist in the application root directory. – KrispyDonuts Aug 14 '13 at 20:08
  • There wouldn't be any way then to somehow place the dll (thats inside my project folder) to the application root directory without referencing the dll? – KrispyDonuts Aug 14 '13 at 20:14

1 Answers1

2

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.

David Kean
  • 5,722
  • 26
  • 26
  • Thanks for the response David! Yes you are correct, it is from your pclcontrib project. I was able to get everything working properly by referencing Portable.Store inside my Windows Store application. However I was trying to remove the need for referencing it inside the Windows Store application. The portable.store.dll would be included with the PCL (but not referenced). And then somehow included with the AppX package. Have you looked into this, if so is this possible? – KrispyDonuts Aug 14 '13 at 21:05
  • There's not a good way to get this working. MSBuild will only package the binary if there is a static dependency somewhere in the grap between the store project and Portable.Store. If you are worried about the complexity of having a project reference multiple binaries, a NuGet package or Extension SDKs (http://msdn.microsoft.com/en-us/library/vstudio/hh768146.aspx) were designed to tackle that. – David Kean Aug 14 '13 at 21:10
  • Unfortunately the project I am working on wouldn't be deployed through NuGet. I think for now I'll just leave it be and reference it in the Windows Store application. But, if I had to get it working, do you know what I could start looking at and how it could be implemented? – KrispyDonuts Aug 14 '13 at 21:15
  • Just saw your edit... So there would be no way to include a dll within the appx without having a dependency? If I'm understanding this correctly. – KrispyDonuts Aug 14 '13 at 21:25
  • Depends, what side of the project do you own? The Store project or the portable project? – David Kean Aug 15 '13 at 00:06
  • And what exactly is your scenario? ie Why do you want users to not have to add a reference Portable.Store? Is it because you want to hide it behind your own binary? – David Kean Aug 15 '13 at 00:21
  • I own both sides of the project. But I would want to be able to give out the portable side as a packaged solution so that other developers would be able to create their own application. The main reason of hiding it behind my own binary is so the application developer would not have to do any additional setup when using the PCL. I know its a small thing having to add Portable.Store as a reference but if I could get it where the developer would just have to add my PCL that would be great (and everything would get setup in terms of the PCL layer) – KrispyDonuts Aug 15 '13 at 13:21