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?)
The answer lies in the build output:
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:
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.