8

I've downloaded the latest .NET Framework and I'm working on .NET Core 2.0 Application on VS 2017 15.8.7. Here are the packages I've installed.

enter image description here

using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
      {

      }

I'm getting an error at this line, saying:

FileNotFoundException: Could not load file or assembly 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Here is my .csproj

 <PackageReference Include="Microsoft.AspNetCore.App" />
 <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
 <PackageReference Include="Microsoft.PowerBI.Api" Version="2.0.14" />
 <PackageReference Include="Microsoft.PowerBI.Core" Version="1.1.11" />
 <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.6" />
 <PackageReference Include="System.Net.Http" Version="4.3.4" />

Why am I getting this error. Is there a reference I can add to make it work?

[UPDATE] I added the following lines in my csproj and am no longer getting this error.

<ItemGroup>
    <Reference Include="System.Net.Http">
      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework\v4.0.30319\System.Net.Http.dll</HintPath>
    </Reference>
    <Reference Include="System.Net.Http.WebRequest">
      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework\v4.0.30319\System.Net.Http.WebRequest.dll</HintPath>
    </Reference>
  </ItemGroup>
7
  • Is your app actually targeting .NET Framework? Commented Oct 11, 2018 at 16:34
  • <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> Commented Oct 11, 2018 at 17:22
  • @MAK I'm having this problem now, did you find a solution? Dotnet core is not the same as .NET Framework, and it is not clear for me right now whether the PowerBI API client is compatible with dotnet core--it builds, but I get this error at runtime. However, I ported my application over to .NET Framework 4.6.1 and I am still getting this error at runtime, so maybe it is something else. Commented Oct 30, 2018 at 15:39
  • @Lopsided From the repository of the project, it seems it requires .Net 4.5 and is not compatible with .Net core at the moment. github.com/Microsoft/PowerBI-CSharp/blob/… Commented Oct 30, 2018 at 18:00
  • @Lopsided. I manually the 2 dll's in the project. Please see update on my question. Commented Oct 31, 2018 at 13:32

3 Answers 3

5
+100

There's your problem. You're targeting .NET Core. The code you're using uses WebRequest under the hood, which doesn't exist in .NET Core. You'll need to target the full framework:

<TargetFramework>net461</TargetFramework>

Or whatever version you want to target. That of course means you can only run this app on a Windows server.

Sign up to request clarification or add additional context in comments.

7 Comments

If I change the Target Framework to net461 I get errors: Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net461. My application is a .net core 2.0 app.
Then try bumping the version to something newer. I'm honestly not sure if any version of .NET Framework is compatible with ASP.NET Core 2.1. If not, you may have to downgrade to 2.0.
@ChrisPratt I gave you the bounty because technically you are correct and this is still the best answer to the question and solution to the problem. HOWEVER, your comments regarding .NET Framework imply some misunderstandings regarding the relationship between .NET Framework, .NET Core, and .NET Standard. Note that .NET Core is a rewrite, and not some "core" portion of the .NET Framework. You may very well know this already (your account is certainly reputable enough to suggest that is the case), but the language you use here is slightly confusing and may mislead other developers.
@Lopsided: I'm not sure I see where the language is confusing. WebRequest exists as essentially a Windows-only API, which means the full framework must be targeted to support the inclusion of the library which uses it. This is the precise reason you get a compiler warning when referencing a .NET Framework library in a project that targets .NET Core: there might be APIs used that are not supported by .NET Core and, more specifically, .NET Standard.
@ChrisPratt Perhaps I am being pedantic, but the phrase "you'll need to target the full framework" implies to me that .NET Framework is an more robust version / implementation of .NET Core. It is the reason I discounted your answer in the first place and went about setting the bounty to bait a more reliable source.
|
2

I know 2 situations where you can get this error:

  • the nuget package is not installed in the "client project" of the solution (it is NOT enough to add dependency to a common/factorized project of the solution; sometimes you need to add the dependency to the project using it, itself)
  • your defined Framework version is not compatible either among all project of your solution, or with the already installed nuget package; you may consider making a big upgrade of all your nuget packages, and check the Framework version defined on each of your projects

1 Comment

Thanks for this. Ran into this issue and your first bullet, adding the nuget pkg to the main client project, fixed our issue.
0

Sometimes it helps to install highest possible version of missing package on NuGet (System.Net.Http). It may happen, that ASP.NET uses different version than PowerBI and binding redirects may be required.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.