How to solve “When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to case values to” while using Fake XRM Easy

Sending
User Review
0 (0 votes)

While using Fake XRM Easy for Plug-in or Workflow unit testing, there could be situations that could arise where we need to use fetchXML to retrieve some records. While it works for most of the time, it can be tricky while working with some attributes statecode for starters.

solve arising error while using Fake XRM Easy

In the above fetchXML, “<condition attribute=”statecode” operator=”eq” value=”0″ />” will throw the error ‘When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to.’ as shown in the below screenshot:

error

To overcome this, we need to generate Early Bound. For that, we will be using the Early Bound Generator plugin of XrmToolBox.

Note: Once you open up the Early Bound Generator, you need to click on Create All button to generate class files for Entities, Actions, and Optionsets. Otherwise, based on your requirement you can decide which one you need to generate.

solve arising error while using Fake XRM Easy

After the process is complete, put those three files (Actions.cs, Entities.cs, Optionsets.cs) in the project you are working and change the namespace of these files to align with your project’s. For a cleaner folder structure, add a folder named Helper or of the same tone in your project and put these files in it.

add helper folder

After you’ve declared the context, you need to add proxy type assembly to your faked context, as shown in the screenshot below:

add proxy type assembly

Note: For feasibility, use the line of code given below.

context.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

Conclusion

Following the above approach, you will be able to use FetchXML to retrieve data without getting ‘When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to.’ error.

click2clone