-1

I've got a project that uses a library (from nuget)
The target framework for my project is currently 4.0

I'm using objects and methods from the library, I get intellisense etc...

However, when I build, compilation fails with

The type or namespace could not be found. Are you missing a using directive or assembly reference?

If I change the target framework of the project to 4.5, it compiles.

Is there a way round this?

EDIT

As a specific example, here are the steps to reproduce this problem in one particular case.

  • File -> New Project
  • New Console application
  • Set Target framework to 4.0

  • Nuget install paymill wrapper

Use one of the types in the Paymill wrapper. For example:

using PaymillWrapper.Models;
using PaymillWrapper.Service;  

public class MyClass
{
    private readonly PaymentService _paymentService;
}

VS doesn't complain.
Compile

Receive error:

The type or namespace name 'ClientService' could not be found (are you missing a using directive or an assembly reference?)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Alex
  • 37,502
  • 51
  • 204
  • 332
  • 1
    I suspect the error message shows the *actual* type or namespace that can't be found. That information is crucial to the question. – Jon Skeet Aug 21 '13 at 21:36
  • It certainly does. But the type is in the library I've referenced. Changing the target framework solves the issue... but that doesn't seem like a solution to me? – Alex Aug 21 '13 at 21:40
  • Gotta love a drive by down-voter. – Alex Aug 21 '13 at 21:41
  • 1
    Well which library is it? Perhaps there are different versions which are used for different targets? Why are you with-holding the relevant information from us? This should be easy to reproduce, but not while you're hiding information. – Jon Skeet Aug 21 '13 at 21:41
  • Not that it's overly relevant, but it's the .net Paymill wrapper. No other target versions are available. I guess will have to change the target framework for all 14 projects in this solution. – Alex Aug 21 '13 at 21:43
  • 2
    "Since I seem to be attracting the wrath of the drive-by downvoters" - you mean "Since my question didn't have enough information in it." The target library in question *is* relevant, as is the type which can't be found. Now that you've posted more information, I can try to reproduce the problem. I don't see why you were so reluctant to do so before, or why you think it's unreasonable that people downvoted your vague question. – Jon Skeet Aug 21 '13 at 21:56
  • There is not much to say. If you open the `PaymillWrapper.csproj ` you could see `v4.5`. So it seems that this library need NET 4.5 – Steve Aug 21 '13 at 21:58
  • Because it was not limited to *this* library. I didn't want to make the question so specific to THIS particular library. Was kind of a more generic question before, not so much now. – Alex Aug 21 '13 at 21:59
  • 1
    @alexjamesbrown: It's specific to "libraries which require .NET 4.5" but we didn't know whether the library in question *did* require .NET 4.5. It could have been some entirely different, obscure problem. By not including any information, you made it harder for people to help you. – Jon Skeet Aug 21 '13 at 22:02

2 Answers2

4

The answer lies in the build output:

2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3274: The primary reference "PaymillWrapper" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "PaymillWrapper" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "PaymillWrapper" or retarget your application to a framework version which contains "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

In other words, the NuGet package uses a reference to .NET 4.5, so you can only use it on .NET 4.5+ projects.

You might want to ask the authors of Paymill Wrapper to see if they could publish a version which targets .NET 4 instead.

Note that the NuGet package page even states this:

Dependencies
- .NETFramework 4.5

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thought as much. Just wanted clarification, didn't articulate the question particularly well – Alex Aug 21 '13 at 21:59
  • @alexjamesbrown: So had you already noticed that build error? If so, why did you not mention it in the question? And why did you think that the NuGet package causing the problem wasn't relevant? – Jon Skeet Aug 21 '13 at 22:01
0

As per the answer by Jon Skeet, the problem is in fact, with the library in question.

It was built against .net 4.5

I submitted a pull request that fixes this.

Alex
  • 37,502
  • 51
  • 204
  • 332