top of page

Error Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' When Using Dependent Assembly Plugins

the following error occurred because the Early Bound Code was in a different assembly. Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'XXX.EarlyBoundCode.Contact' occurs when using the new Dependent Assembly plugin, where the plugin is a diffrent assembly to the early bound code.

The new Dependent Assembly plugin allows one or more external assemblies to be packaged with the plugin. This allows two benefits. Firstly the biggest benefit, is no more IL Merging to add required assemblies—secondly, more professional code structure. Such as separating reusable code into a shared assembly which can be used with multiple plugins. https://learn.microsoft.com/en-us/power-platform-release-plan/2022wave1/data-platform/dependent-assemblies-plug-ins


To create a Dependent Assembly plugin Visual Studio Project execute pac plugin init command using the PAC CLI. https://learn.microsoft.com/en-us/power-platform/developer/cli/reference/plugin#pac-plugin-init

I have separated plugin assemblies by features, to enable deployment of features in isolationation. We started using Dependent Assembly plugins so duplicated/reusable code can be refactored into a shared assembly. The shared assembly also included the early bound code.


However, the following error occurred because the Early Bound Code was in a different assembly. Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'XXX.EarlyBoundCode.Contact' occurs when using the new Dependent Assembly plugin, where the plugin is a diffrent assembly to the early bound code.


As it took considerable effort to find a solution to this error I want to share the solution, which is to initialize the organisation service using the service factory and "wire up" the early bound types using the ProxyTypesAssembly as per the code below.


I have put this into a reusable extension method so it is a single call for each plugin, I might add this and other plugin helper methods to GitHub in the future. The original solution was found here, https://powerusers.microsoft.com/t5/Power-Apps-Pro-Dev-ISV/Multiple-plugin-assemblies-inside-Nuget-package-and-LINQ-query/m-p/2427714#M9413








181 views0 comments

Recent Posts

See All

Opmerkingen


bottom of page