Using NuPack.Core for an external application

Nov 16, 2010 at 2:09 AM


I am trying to use NuPack.Core for a little commandline application but I keep getting some strange exception.

For example with this little program, when run inside visual studio (where FileSystem and PackagePath resolver are simple implementations of their respective interfaces where all members just throw NotImplementedException, but none of them are called anyway):


var repository = new DataServicePackageRepository(new Uri(""));
var fs = new FileSystem();
var resolver = new PackagePathResolver();
var manager = new PackageManager(repository, resolver, fs);


I keep getting the following exception (which I always get at the EnsureManifest() call inside the ZipPackage function - and it seems if started outside visual studio it runs without this exception):

System.TypeLoadException was unhandled by user code
  Message=Inheritance security rules violated while overriding member: 'NuGet.ManifestMetadata.Validate(System.ComponentModel.DataAnnotations.ValidationContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
       at NuGet.ZipPackage.EnsureManifest()
       at NuGet.ZipPackage..ctor(Func`1 streamFactory) in P:\Projects\nuget\NuPack.Core\Packages\ZipPackage.cs:line 34
       at NuGet.ZipPackageFactory.CreatePackage(Func`1 streamFactory) in P:\Projects\nuget\NuPack.Core\Utility\ZipPackageFactory.cs:line 7
       at NuGet.PackageDownloader.DownloadPackage(Uri uri, Byte[] packageHash, Boolean useCache) in P:\Projects\nuget\NuPack.Core\Utility\PackageDownloader.cs:line 45
       at NuGet.PackageDownloader.DownloadPackage(Uri uri) in P:\Projects\nuget\NuPack.Core\Utility\PackageDownloader.cs:line 35
       at NuGet.DataServicePackageRepository.<>c__DisplayClass3.<DownloadAndVerifyPackage>b__1() in P:\Projects\nuget\NuPack.Core\Repositories\DataServicePackageRepository.cs:line 44
       at System.Lazy`1.CreateValue()


Any idea what may cause it?


Nov 16, 2010 at 2:12 AM

Yes, this is a known issue that only happens when debugging. To work around it, you can remove the security transparent attribute from NuGet.Core/Properties/AssemblyInfo.cs and try again. We're hoping to get his fixed in a future version of the framework.

Nov 16, 2010 at 2:15 AM

Any idea what is causing it? Just being curious....

Nov 16, 2010 at 3:08 AM

DataAnnotations is marked as security critical and NuGet.Core is marked as transparent.