Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.Compression in ASP.NET VNext full CLR

I'm trying to use System.IO.Compression.ZipArchive in a ASP.NET VNext class library in VS2015 Preview. I added the System.IO.Compression package using NuGet, and it added it to my project.json as a aspnetcore50 dependency.

When I try to use the ZipArchive, the intellisense says is not available in ASP.NET 5.0 but it is available in ASP.NET Core 5.0. If I switch to use ASP.NET Core using the drop down in the top bar, then my code works as expected, but when I choose normal ASP.NET it doesn't work.

I tried manually adding it as a dependency to aspnet50 in the project.json, but that didn't fix it.

I need to use the full CLR over the Core CLR as I need to load assemblies into the AppDomain at run time, and I believe this isn't supported in the Core CLR.

Please could someone explain what's going on here, maybe point me to some articles or blog posts, show me how to fix this.

Update: I guess a better way or wording this is - the ZipArchive is not available in aspnet50, but it is available in aspnetcore50 when I add the System.IO.Compression NuGet package. Why is this?

like image 797
Tom Avatar asked Nov 25 '14 10:11

Tom


1 Answers

They only way that I get the project to compile and work was doing the following in the project.json. I'm not too familiar with the compression library so I did not spend time trying to compress a file. Below you will a sample code that will compile with no issue.


{
    "version": "1.0.0-*",
    "dependencies": {

    },

    "frameworks": {
        "aspnet50": {
            "dependencies": {

            },
            "frameworkAssemblies": {                
                "System.IO.Compression": "4.0.0.0"

            }
        },
        "aspnetcore50": {
            "dependencies": {
                "System.Runtime": "4.0.20-beta-22231",                
                "System.IO.Compression.ZipFile": "4.0.0-beta-22231",
                "System.IO": "4.0.10-beta-22231",
                "System.IO.FileSystem": "4.0.0-beta-22231"

            }
        }
    }
}

Sample Code

    public static void ZipFile(string path)
    {
        var data = new MemoryStream(File.ReadAllBytes(path));
        var zip = new ZipArchive(data, ZipArchiveMode.Create,false);
        zip.CreateEntry(path + ".zip");            
    }
like image 172
Son_of_Sam Avatar answered Nov 18 '22 20:11

Son_of_Sam