0
ServiceReference1.Service1Client ser = new ServiceReference1.Service1Client();
        List<OneTimeWorkout> list = ser.GetOneTimeWorkouts().ToList();    

I'm trying to get list of OneTimeWorkout objects, however I get this error:

Cannot implicitly convert typ System.Collections.Generic.List<WN.Manager.ServiceReference1.OneTimeWorkout> to System.Collections.Generic.List<WN.Models.OneTimeWorkout>

My service reference is configured to reuse types in all referenced assemblies.

My service method:

public List<OneTimeWorkout> GetOneTimeWorkouts()
{
    return new BusinessLogic.BusinessLogic().GetOneTimeWorkouts();
}   

Another problem is that I cannot create

var list = ser.GetOneTimeWorkouts().ToList();   

instead of generic list because later I do need to pass it for another method and var list seems not to be working (still the same error)

There were several similar questions already asked in stackoverflow, yet none of these answers seems to be working for me.

venerik
  • 5,766
  • 2
  • 33
  • 43

1 Answers1

1

The fact that your error mentions WN.Manager.ServiceReference1.OneTimeWorkout indicates your service reference does not reuse the types of the referenced assemblies.

You can change the service reference by selecting it in the Solution Explorer and choose Configure Service Reference. In the dialog make sure Reuse types in referenced assemblies is checked.

venerik
  • 5,766
  • 2
  • 33
  • 43
  • Hello, that was the answer of similar questions in StackOverflow. However, I made sure to check the dialog box to Reuse types in referenced assemblies. Unfortunately, that doesn't help either – Tautvydas Versockas Oct 10 '15 at 08:10
  • Then I suspect the consuming project (WN.Manager) doesn't have a 'normal' reference to the providing project (WN.Models). – venerik Oct 10 '15 at 08:15
  • That's what I thought at first! However, it does. – Tautvydas Versockas Oct 10 '15 at 08:15
  • Very strange. In this case I would delete the Service Reference from WM.Manager, double check that WM.Models is a referenced by WM.Manager. Add a service reference to WM.Manager again. Just to be sure. – venerik Oct 10 '15 at 08:21
  • Re-adding service reference didn't help. However, I deleted WN.Models references and added them once again (in WN.Service and WN.Manager) It seems to be working now. Still can't understand, why did the problem occur – Tautvydas Versockas Oct 10 '15 at 08:28