However, this solution has a few issues. It does not handle Portable Class Libraries (PCLs) and does not show how to support loading symbols from embedded pdb-files either. The code presented below handles both.

As with the solution Jeffrey Richter details, one simply adds a handler to the current domains AssemblyResolve event, which is called whenever an assembly could not be resolved directly. However, this also occurs when an embedded portable class library (such as Autofac) has defined a dependency towards any BCL assembly (e.g. System.Core 2.0.5.0), in this case you have to check if the assembly is retargetable and then load it directly via the usual CLR mechanism so the appropriate version is loaded.

For a better debug experience and better exception stack traces it is recommended to include pdb-files as well. pdb-files are handled by simply loading these if they have been embedded, have the same name as the dll-file and then using the Assembly.Load overload that also loads raw symbol data from a byte array.

To use the code do the following:

Call SetupEmbeddedAssemblyResolve as the first thing in your application

Add dependencies incl. pdb-files, if needed, to your project via Add as Link and change the build action to Embedded Resource and Copy to Output Directory to Do not copy

Change the assembly references properties under References and set Copy Local to false