cancel
Showing results for 
Search instead for 
Did you mean: 

System.Text.Json API support for Plugins

Given the increasing number of integrations that Power Platform / D365 have with external services that have the capacity to write structured JSON back to CommonDataService record fields, it would be greatly beneficial to be able to replace the System.Runtime.Serialization.Json WCF APIs in plugins with the new System.Text.Json API which is v4.6.2 compatible.

 

Whilst where possible we endeavour to use Azure Functions or logic apps, this is not possible for existing synchronous plugins.

 

This could be achieved by adding the System.Text.Json DLL to the cloud implementation GAC.

Status: New
Comments
MichaelHolmesWP
Regular Visitor

Thanks to Microsoft, it appears support for this has been added when they updated their Core SDK NuGets to support System.Text.Json !

Jadyn
New Member

Hi @MichaelHolmesWP,

 

I tested it with `CustomAPI` plugin. It doesn't work. I get some errors.

Can you use it in a plugin? 

 

I used `pac plugin init` to create it.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <PowerAppsTargetsPath>$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\PowerApps</PowerAppsTargetsPath>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>Test.CustomAPIs.snk</AssemblyOriginatorKeyFile>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <FileVersion>1.0.0.0</FileVersion>
    <ProjectTypeGuids>{4C25E9B5-9FA6-436c-8E19-B395D2A65FAF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  </PropertyGroup>

  <Import Project="$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Plugin.props" Condition="Exists('$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Plugin.props')" />

  <ItemGroup>
    <PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.*" />
    <PackageReference Include="Microsoft.PowerApps.MSBuild.Plugin" Version="1.*" />
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
  </ItemGroup>

  <Import Project="$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Plugin.targets" Condition="Exists('$(PowerAppsTargetsPath)\Microsoft.PowerApps.VisualStudio.Plugin.targets')" />
</Project>

 

When `JsonSerializer.Serialize(obj)` is called, the following exception is thrown.

 

Plugin Exceptions trace

 

System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Could not load file or assembly 'System.Text.Json, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (Fault Detail is equal to Exception details: 
ErrorCode: 0x80040224
Message: Could not load file or assembly 'System.Text.Json, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
TimeStamp: 2022-05-27T09:47:59.4741936Z
OriginalException: PluginExecution
ExceptionSource: PluginExecution
--
).