onsdag 4 oktober 2017

Business process error from custom workflow activity

Last week I was working on a custom workflow activity which was reading some data from CRM and returned a string which was going to be but into an email. This shouldn't be a big operation but I still encountered errors which I hadn't seen before.

The error message that was thrown to me was  System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'. Now that's not very informative at all.
Since this was a Dynamics 365 online I'd thought that there might be a ton of stuff that wasn't really working together and I was REALLY going through the code to see what I had written but didn't really find anything weird, just your average custom workflow activity input and output really.

Enter search engine again. https://connect.microsoft.com/VisualStudio/feedback/details/1097462/missingmethodexception-additional-information-method-not-found-0-system-array-empty gave me some pointers where the .NET team responded the following:

Hi

Most likely what is happening is that:
- The code is compiling against .NET 4.6, where the reference assemblies include Array.Empty<T>().
- The Roslyn compiler sees that Array.Empty<T> is available and so uses it when generating the empty array needed for the params.
- The compiled app is trying to run on .NET 4.5 where Array.Empty doesn’t exit.

If the above is not the case, please let us know. Otherwise, this is by-design.

Thank you,
Alex
.NET Framework

Ok, that was at least pointing to somewhere. I was in fact using .NET 4.6 since it was the default version in VS 2015 and I didn't really think about that and I thought that the Dynamics server would support it. When I changed the .NET version to 4.5.1 it started working as I hoped it would so, new stuff isn't always the way to go.

Rickard Norström
Developer at CRM-Konsulterna
www.crmkonsulterna.se 

Inga kommentarer:

Skicka en kommentar