Search code examples
c#dynamics-crm

CloseQuoteRequest throwing exception


I am trying to close a quote in MSCRM using C# CloseQuoteRequest.

CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = quote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString(),
    },
    Status = new OptionSetValue(-1),
    RequestName = "CloseQuote",
};
Service.Execute(closeQuoteRequest);

I am getting the error;

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 711. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'CRM.Entities.Entities:QuoteClose'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'QuoteClose' and namespace 'CRM.Entities.Entities'.'. Please see InnerException for more details.

There is no inner exception for me to see.


Solution

  • I don't know why this was the case but adding .ToEntity() to the QuoteClose Entity worked.

    CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
    {
        QuoteClose = new QuoteClose()
        {
            QuoteId = quote.ToEntityReference(),
            Subject = "Quote Close " + DateTime.Now.ToString(),
        }.ToEntity<Entity>(),
        Status = new OptionSetValue(-1),
        RequestName = "CloseQuote",
    };
    Service.Execute(closeQuoteRequest);