Sebastian
Sebastian

Reputation: 51

Microsoft.Net.Http.Headers 3.0.0 does not exist but is required when upgrading to .net core 3.0

I followed the tutorial on upgrading .net core 2.2 to 3.0.

When i run my solution an error is thrown:

[CS0012] The type 'MediaTypeHeaderValue' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Net.Http.Headers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

It is thrown in my DownloadFile function:

public FileStreamResult DownloadFile(int id)
{
    ...

    return new FileStreamResult(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read), fm.ContentType);
}

The issue is, Microsoft.Net.Http.Headers, Version=3.0.0.0 does not exist in this version and i cannot find anyone else having the same problem. Since the download function is very simple and seems to be used in other projects on github i don't think it is a wrong implementation.

Upvotes: 3

Views: 569

Answers (1)

Sebastian
Sebastian

Reputation: 51

After a deep dive into .net core dependencies it appears that the Microsoft.Net.Http.Headers package has been moved into the .net core lib. After adding the references manually in the .csproj file i can build again.

<ItemGroup>
    ...
    <Reference Include="Microsoft.Net.Http.Headers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"/>
</ItemGroup>

Upvotes: 2

Related Questions