Hi all,

Today i rather had a strange problem, where one of my Visual Studio package failed to compile with the following error

1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error : CreatePkgDef : error : ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at System.Reflection.RuntimeModule.GetTypes()
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at System.Reflection.Assembly.GetTypes()
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at Microsoft.VisualStudio.Tools.CreatePkgDef.ProcessAssembly(String fileName, Hive hive, PkgDefContext context, Boolean register, RegistrationMode mode) in f:\dd\VSSDK\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 260
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at Microsoft.VisualStudio.Tools.CreatePkgDef.DoCreatePkgDef(InputArguments inputArguments) in f:\dd\VSSDK\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 164
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error :    at Microsoft.VisualStudio.Tools.CreatePkgDef.Main(String[] arguments) in f:\dd\VSSDK\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 85
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets(761,5): error : Could not load file or assembly 'foobar, Version=1.0.5562.28500, Culture=neutral, PublicKeyToken=106332a6f3dda443' or one of its dependencies. The specified module could not be found.

After some time debugging the issue, i figured out that the PkgDef MSBuild task tried to load the type during the build process, and eventually fails to load the dependencies of this assembly. The fix is to resolve the missing dependencies and building the project again.