Errore Fatale
Errore Fatale

Reputation: 988

WCF is calling a non existing service implementation

I created a WCF service one months ago in my solution.

Project where I have service contract and the implementation: ServiceContract.csproj

Service contract: IUserManagementService

Service implementation: UserManagementService

Service client: UserManagementServiceClient

Service hosting project: ServiceLayer.csproj

I am using visual studio pro 2013 and my solution targets the net framework 4.5.2. The solution (and projects related to the service) were created with Visual Studio Express 2015, and since 2 weeks ago I'm using Visual Studio Professional 2013. The migration of the solution was successfull.

Everything worked fine until one week ago. I have written a lot of code during the last month and debugged it succesfully, with the service perfectly working.

One week ago, I started to have issues when calling a particular method (GetUserInfoByUserName) of my service: UserManagementService.cs not found + MissingMethodException.

http://s1.postimg.org/ol4olperz/Cattura.png

I tried to click on "Browse and find UserManagementService.cs", a window appeared: "The source file is different from wwhen the module was built. Would you like the debugger to use it anyway (yes/no)?" (choosing "yes" doesn't solve the problem).

MissingMethodException is caused by the call of the constructor of UnserInfoDTO (a class which stays in an other project).

So I started troubleshooting, and I found out the following facts:

1) If I call other methods of the service, I don't get any error. But WCF is calling an older version of the methods. I modified all methods by replacing the whole code in their body with "throw new Exception". The exceptions are not thrown. The program follows the old instructions. Of course the same is true for the method GetUserInfoByUserName(string userName): the exception (Exception) is not thrown. MissingMethodException is thrown, because the method is still executing the old code where I have the call to the constructor of UserInfoDTO.

2) If I directly call UserManagementService, by simply creating an instance of it in the client, everything works fine. In other words, I have issues only when I call the service through the service client (UserManagementServiceClient).

3) It seems that the code of ServiceContract project (where I have the service contract and it's implementation, with which I have issues) is correctly compiled. This fact is quite obvious (see the point 2), but I wanted to be 100% sure, so I opened the module window while debugging: Debug ---> Windows ---> Modules, where I can read all dll which were loaded. The weight of ServiceContract.dll was 16 Kb. I did this experiment: I added new code in the service contract and in the service implementation (UserManagementService) and I rebuilt the solution. I started an other debug session and looked at the loaded dll: the weight of ServiceContract.dll was 18 Kb, therefore the compiled code has been updated with the new C# code. This means that I'm not loading an older version of the dll when debugging.

4) The problem shouldn't be in the service client implementation. The client service was generated with svcutil. For troubleshooting, I created a new consumer in the same solution (a simple console application), and this time I generated the service client with "Add service reference". I have the same identical issues with this consumer.

5) I tried to change the port of the web site where the service is hosted: from 57915 to 57916, to exclude that the problem was not related with the fact that are is other website with the same port (57915). Of course I updated the config file of the consumer accordingly. The problem was not solved with this action.

6) I tried to remove UserManagementService.cs from the project and realod it. Unsuccesfull.

7) I tried to remove ServiceContract.proj from the solution, creating a new project, copying the code of the removed project in the new project. Unsuccesfull.

Here below the code of the service contract (IUserManagementService), project ServiceContract.csproj

namespace ERP.ServiceContract
{
    [ServiceContract]
    public interface IUserManagementService
    {
        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUsers", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUsersResponse")]
        IEnumerable<UserDTO> GetAllUsers();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUserInfoResponse")]
        IEnumerable<UserInfoDTO> GetAllUserInfo();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUser", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserResponse")]
        void AddUser(UserDTO user);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUser", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserResponse")]
        void ModifyUser(UserDTO user);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserInfoByUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserInfoByUserNameResponse")]
        UserInfoDTO GetUserInfoByUserName(string userName);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserInfoResponse")]
        void AddUserInfo(UserInfoDTO user_info);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserInfoResponse")]
        void ModifyUserInfo(UserInfoDTO user_info);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/VerifyLogin", ReplyAction = "http://tempuri.org/IUserManagementService/VerifyLoginResponse")]
        UserDTO VerifyLogin(string userName, string password);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/AddPerson", ReplyAction = "http://tempuri.org/IUserManagementService/AddPersonResponse")]
        void AddPerson(PersonDTO person);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/Filter", ReplyAction = "http://tempuri.org/IUserManagementService/FilterResponse")]
        IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUser", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserResponse")]
        IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUsersTree", ReplyAction = "http://tempuri.org/IUserManagementService/GetUsersTreerResponse")]
        IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserInfoResponse")]
        IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO userInfo);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetCityNameByCAP", ReplyAction = "http://tempuri.org/IUserManagementService/GetCityNameByCAPResponse")]
        string GetCityNameByCAP(string CAP);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesNames", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesNamesResponse")]
        IEnumerable<string> GetAllCitiesNames();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPs", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPsResponse")]
        IEnumerable<string> GetAllCitiesCAPs();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyPerson", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyPersonResponse")]
        void ModifyPerson(PersonDTO person);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidatePerson", ReplyAction = "http://tempuri.org/IUserManagementService/ValidatePersonResponse")]
        IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllPeople", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllPeopleResponse")]
        IEnumerable<PersonDTO> GetAllPeople();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/PersonWithEmailExists", ReplyAction = "http://tempuri.org/IUserManagementService/PersonWithEmailExistsResponse")]
        bool PersonWithEmailExists(string email);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserNameResponse")]
        PersonDTO GetPersonAssociatedToUserWithUserName(string userName);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCities", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesResponse")]
        IEnumerable<CityDTO> GetAllCities();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCountriesKeys", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCountriesKeysResponse")]
        IEnumerable<string> GetAllCountriesKeys();

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserWithUserNameResponse")]
        void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserData", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserDataResponse")]
        IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserNameResponse")]
        string GetUserRoleOfUserWithUserName(string userName);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/AddRecord", ReplyAction = "http://tempuri.org/IUserManagementService/AddRecordResponse")]
        void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateRecord", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateRecordResponse")]
        IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateContract", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateContractResponse")]
        IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContract", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractResponse")]
        ContractDTO GetContract(string id);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKeyResponse")]
        ContractDTO GetContractAssociatedWithUserInfoWithKey(string key);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKeyResponse")]
        string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key);

        [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonFullName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonFullNameResponse")]
        string GetPersonFullName(string email);
    }
}

Here below the old service contract implementation (UserManagementService)

namespace ERP.ServiceContract
{
    public class UserManagementService : IUserManagementService
    {
        private IUserManagement _userManager = UserManagement.GetInstanceForDatabase();

        public IEnumerable<UserInfoDTO> GetAllUserInfo()
        {
            return Converter.ConvertEachElementToDTO(_userManager.GetAllUserInfo());
        }

        public IEnumerable<UserDTO> GetAllUsers()
        {
            var users = _userManager.GetAllUsers();

            //foreach(UserBDO user in users)
            //{
            //    user.UserManager = _userManager;
            //    user.InitializeCreatedUsers();
            //}

            return Converter.ConvertEachElementToDTO(users);
        }

        public void AddUser(UserDTO user)
        {
            _userManager.AddUser(user.ToBDO());
        }

        public void AddUserInfo(UserInfoDTO user_info)
        {
            _userManager.AddUserInfo(user_info.ToBDO());
        }

        public IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate)
        {
            return GetAllUsers().Where(predicate);
        }

        public UserInfoDTO GetUserInfoByUserName(string userName)
        {
            return _userManager.GetUserInfoByUserName(userName).ToDTO();
        }

        public void ModifyUser(UserDTO user)
        {
            _userManager.ModifyUser(user.ToBDO());
        }

        public void ModifyUserInfo(UserInfoDTO user_info)
        {
            _userManager.ModifyUserInfo(user_info.ToBDO());
        }

        public IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidateUser(user.ToBDO()));
        }

        public UserDTO VerifyLogin(string userName, string password)
        {
            UserBDO result = _userManager.VerifyLogin(userName, password);

            if (result == null)
            {
                return null; 
            }

            return result.ToDTO();
        }

        public IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser)
        {
            throw new Exception();
            return Converter.ConvertEachElementToDTO(_userManager.GetUsersTree(currentUser.ToBDO()));
            return null;
        }

        public IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO info)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidateUserInfo(info.ToBDO()));
        }


        public string GetCityNameByCAP(string CAP)
        {
            return _userManager.GetCityNameByCAP(CAP);
        }

        public IEnumerable<string> GetAllCitiesNames()
        {
            return _userManager.GetAllCitiesNames();
        }

        public IEnumerable<string> GetAllCitiesCAPs()
        {
            return _userManager.GetAllCitiesCAPs();
        }

        public void AddPerson(PersonDTO person)
        {
            _userManager.AddPerson(person.ToBDO());
        }

        public void ModifyPerson(PersonDTO person)
        {
            _userManager.ModifyPerson(person.ToBDO());
        }

        public IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidatePerson(person.ToBDO()));
        }

        public IEnumerable<PersonDTO> GetAllPeople()
        {
            return Converter.ConvertEachElementToDTO(_userManager.GetAllPeople());
        }

        public bool PersonWithEmailExists(string email)
        {
            return _userManager.PersonWithEmailExists(email);
        }

        public PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
        {
            PersonBDO result = _userManager.GetPersonAssociatedToUserWithUserName(userName);

            if (_userManager.GetPersonAssociatedToUserWithUserName(userName) == null)
            {
                return null;
            }

            return result.ToDTO();
        }

        public IEnumerable<CityDTO> GetAllCities()
        {
            return Converter.ConvertEachElementToDTO(_userManager.GetAllCities());
        }

        public IEnumerable<string> GetAllCountriesKeys()
        {
            return _userManager.GetAllCountiresKeys();
        }

        public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = default(DateTime?), bool? active = default(bool?), bool? deleted = default(bool?), string fk_creator = null)
        {
            _userManager.ModifyUserWithUserName(userName, password, name, roleKey, registrationDate, active, deleted, fk_creator);
        }

        public IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidateUserData(userName, password, name, roleKey, fk_creator));
        }


        public string GetUserRoleOfUserWithUserName(string userName)
        {
            return _userManager.GetUserRoleOfUserWithUserName(userName);
        }

        public void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
        {
            _userManager.AddRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey);
        }

        public IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidateRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey));
        }


        public IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract)
        {
            return Converter.ConvertEachElementToDTO(_userManager.ValidateContract(contract.ToBDO()));
        }

        public ContractDTO GetContract(string id)
        {
            ContractBDO result = _userManager.GetContract(id);

            if (result != null)
            {
                return result.ToDTO();
            }

            return null;
        }


        public ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
        {
            ContractBDO result = _userManager.GetContractAssociatedWithUserInfoWithKey(key);

            if (result == null)
            {
                return null;
            }

            return result.ToDTO();
        }


        public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
        {
            return _userManager.GetContractKeyOfContractAssociatedWithUserInfoWithKey(key);
        }

        public string GetPersonFullName(string email)
        {
            return _userManager.GetPersonFullName(email);
        }
    }
}

Here below the new, actual service implementation used for troubleshooting, prohect ServiceContract.csproj

namespace ERP.ServiceContract
{
    public class UserManagementService : IUserManagementService
    {
        public void GetUsersTree()
        {
            throw new Exception();
        }

        public IEnumerable<DTO.UserDTO> GetAllUsers()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.UserInfoDTO> GetAllUserInfo()
        {
            throw new NotImplementedException();
        }

        public void AddUser(DTO.UserDTO user)
        {
            throw new NotImplementedException();
        }

        public void ModifyUser(DTO.UserDTO user)
        {
            throw new NotImplementedException();
        }

        public void AddUserInfo(DTO.UserInfoDTO user_info)
        {
            throw new NotImplementedException();
        }

        public void ModifyUserInfo(DTO.UserInfoDTO user_info)
        {
            throw new NotImplementedException();
        }


        public void AddPerson(DTO.PersonDTO person)
        {
            throw new NotImplementedException();
        }

        public DTO.UserDTO VerifyLogin(string userName, string password)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.UserDTO> Filter(Func<DTO.UserDTO, bool> predicate)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidateUser(DTO.UserDTO user)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.UserDTO> GetUsersTree(DTO.UserDTO currentUser)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidateUserInfo(DTO.UserInfoDTO userInfo)
        {
            throw new NotImplementedException();
        }

        public string GetCityNameByCAP(string CAP)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<string> GetAllCitiesNames()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<string> GetAllCitiesCAPs()
        {
            throw new NotImplementedException();
        }

        public void ModifyPerson(DTO.PersonDTO person)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidatePerson(DTO.PersonDTO person)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.PersonDTO> GetAllPeople()
        {
            throw new NotImplementedException();
        }

        public bool PersonWithEmailExists(string email)
        {
            throw new NotImplementedException();
        }

        public DTO.PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.CityDTO> GetAllCities()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<string> GetAllCountriesKeys()
        {
            throw new NotImplementedException();
        }

        public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
        {
            throw new NotImplementedException();
        }

        public string GetUserRoleOfUserWithUserName(string userName)
        {
            throw new NotImplementedException();
        }


        public void AddRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidateRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<DTO.ValidationErrorDTO> ValidateContract(DTO.ContractDTO contract)
        {
            throw new NotImplementedException();
        }

        public DTO.ContractDTO GetContract(string id)
        {
            throw new NotImplementedException();
        }

        public DTO.ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
        {
            throw new NotImplementedException();
        }

        public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
        {
            throw new NotImplementedException();
        }

        public string GetPersonFullName(string email)
        {
            throw new NotImplementedException();
        }

        public DTO.UserInfoDTO GetUserInfoByUserName(string userName)
        {
            throw new NotImplementedException();
        }
    }
}

UserManagementService.svc, project ServiceLayer.csproj

<%@ ServiceHost Language="C#" Debug="true" Service="ERP.ServiceContract.UserManagementService"  %>

Program demo, project consumer.csproj

namespace Consumer
{
    class Program
    {
        static void Main(string[] args)
        {
            //Works fine
            UserManagementService service = new UserManagementService();
            service.GetUserInfoByUserName("AGIE");

            //Works fine
            service.GetAllCities();

            ServiceReference.UserManagementServiceClient proxy = new ServiceReference.UserManagementServiceClient();

            //Error UserManagementService.cs not found + MissingMethodException. NotImplementedException is not thrown
            proxy.GetUserInfoByUserName("AGIE");

            //Error UserManagementService.cs not found + MissingMethodException does not occur, but the NotImplementedException of the method is not thrown
            proxy.GetAllCities();
        } 
    }
}

Upvotes: 1

Views: 84

Answers (1)

Errore Fatale
Errore Fatale

Reputation: 988

I solved the problem.

There was an old dll in my solution which caused the problem.

If you are reading this question because you have a similar problem, check that there are not old dll (or executable code in general) in all projects of the solution (bin and obj folders).

Upvotes: 1

Related Questions