Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

GZip Error with Code First - .NET Framework

RSS
Modified on Tue, Apr 09, 2013, 6:36 PM by Administrator Categorized as ASP·NET MVC, ASP·NET Web Forms, ·Net Framework

Problem

When running a solution that uses Entity Framework Code First, the following error is encountered: "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."

Cause

The cause is a value in the Model column of the __MigrationHistory table. This typically happens if you insert rows in their via a SQL script instead of using UPDATE-DATABASE within Visual Studio's Package Manager.

Solution

The SQL script should be constructed as follows. Note that the CONVERT function call MUST have the third parameter.

delete from dbo.[__MigrationHistory] where MigrationId = '201304042210224_MyMigration'

INSERT INTO dbo.[__MigrationHistory] (MigrationId, Model, ProductVersion)
select
     MigrationId    = '201304042210224_MyMigration' 
    ,Model          = CONVERT(varbinary(max),   
                        '0x1F8B0800000000000...'
                        ,1)
    ,ProductVersion = '5.0.0.net45'
where not exists (
    select 2 
    from dbo.[__MigrationHistory] 
    where MigrationId = '201304042210224_MyMigration'
    )

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.