Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio report a lambda error in a working WebAPI code on .Net Core?

I migrated an WebAPI from FullDotnet (4.6) to .Net Core 2.0 and I'm having this issue in my Data Layer using Dapper.

My code:

public List<Doctor> GetList()
{
    List<Doctor> ret;
    using (var db = GetMySqlConnection())
    {
        const string sql = @"SELECT D.Id, D.Bio, D.CRMState, D.CRMNumber,
        U.Id, U.Email, U.CreatedOn, U.LastLogon, U.Login, U.Name, U.Phone, U.Surname, U.Id, U.Birth, U.CPF,
        S.Id, S.Name
        from Doctor D
        inner join User U on U.Id = D.UserId
        inner join Speciality S on S.Id = D.IDEspeciality
        order by D.Id DESC";

        ret = db.Query<Doctor, User, Speciality, Doctor>(sql, (doctor, user, speciality) =>
        {
            doctor.User = user;
            doctor.Speciality = speciality;
            return doctor;
        }
        , splitOn: "Id, Id", commandType: CommandType.Text).ToList();
    }
    return ret;
}

Strange Behavior:

PrintScreen from code

The solution Builds and WORK The "error" who VisualStudio highlight is:

Argument type 'lambda expression' is not assignable to parameter type 'System.Func`5'

I have another classes with the same behavior and same error, but, again, the code compile and work, but this "error highlight" is annoying!

This highlight I don't have in my old solution running .NET Framework 4.6

Usefull info:

  • Class Library: .Net Standard 2.0
  • Visual Studio 2017 v15.4.1
  • Resharper 2017.2
like image 980
Thiago Loureiro Avatar asked Oct 26 '17 12:10

Thiago Loureiro


1 Answers

So as we figured it out in the comments, the issue was caused by ReSharper (2017.2).

Some additional steps you can take when suspecting that ReSharper is acting up.

Suspend/resume ReSharper

Just to confirm that ReSharper is causing issues, you can suspend it using:

Tools/Options.../Resharper node/Suspend now

In this case doing a suspend/resume cycle was enough and solved the issue.

Clearing ReSharper cache (source)

Broken caches affect ReSharper behavior. For example, ReSharper can stop resolving symbols or some navigation commands can be unavailable. If you notice such strange behavior, clearing caches for the current solution could help in most cases.

To clear caches for the current solution

  1. Open the solution with supposedly broken caches in Visual Studio.
  2. Open the Environment | General page of ReSharper options.
  3. Click Clear caches. Note that the caches will be only cleaned in the currently selected cache location.
  4. Reopen your solution for the changes to take effect.

ReSharper also cleans up solution caches automatically if a specific solution was not open for more than 30 days.

What if the above doesn't work?

If you confirmed that it's a ReSharper issue, then you should first try and update to the latest version of ReSharper and try to reproduce your problem.

If the issue still persists, then you should head to the JetBrains bug tracker and file an issue after confirming that it's not an already reported bug.

like image 154
Szabolcs Dézsi Avatar answered Nov 10 '22 23:11

Szabolcs Dézsi