web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Dynamics 365 Plugin error "System.Exception: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'Microsoft.SharePoint.Client.Folder'."

(1) ShareShare
ReportReport
Posted on by 383

Hello All,

I built a plug-in which moves sharepoint document library folders. all my code is working well in a console app ,but receiving this below error in a plug-in.  Any recommendations would be great. this plugin also has another method which updates the  document property, which works good. i used ilmerge to comine dll's.

code :

var folder = context.Web.GetFolderByServerRelativeUrl(sourcefolderurl);
var subfolders = context.Web.GetFolderByServerRelativeUrl(sourcefolderurl).Folders;
var files = context.Web.GetFolderByServerRelativeUrl(sourcefolderurl).Files;
context.Load(folder);
context.Load(files);
context.Load(subfolders);
context.ExecuteQuery();
tracingService.Trace("2A");
FolderCollection subfolders1 = folder.Folders; //sub folders (ex: orders,oppotunities)
tracingService.Trace("2B");
if (subfolders.Count > 0) //if Account folder having sub-folders.
{
foreach (Folder sf in subfolders1) //before this line code is breaking.
{
tracingService.Trace("2D");
if (sf.Name != null)
{
tracingService.Trace("2E");
GetSubfolderFiles(context, sf.ServerRelativeUrl, sf.Name);//fetch files inside subfolder
}

}
}

Error:


Error Message:

Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): xxxxxxxxxxxxxxx: System.Exception: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'Microsoft.SharePoint.Client.Folder'.
at Microsoft.Xrm.RemotePlugin.Client.Interceptors.SandboxFabricClientTelemetryInterceptor.<>c__DisplayClass2_0.<Intercept>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.Client.Interceptors.SandboxFabricClientTelemetryInterceptor.Intercept(IInvocation invocation, IExecutionContext context, SandboxFabricCallTracker sandboxFabricCallTracker)
at Microsoft.Xrm.RemotePlugin.Client.Interceptors.SandboxFabricCodeUnitExecuteBaseInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.ISandboxFabricCodeUnitProxy.Execute(ILifetimeScope scope, IExecutionContext context, SandboxFabricCallTracker& sandboxFabricCallTracker)
at Microsoft.Xrm.RemotePlugin.Client.SandboxFabricPlugin.<>c__DisplayClass5_1.<Execute>b__3()
at Polly.Policy.<>c__DisplayClass150_0`1.<Execute>b__0(Context ctx, CancellationToken ct)
at Polly.Policy.<>c__DisplayClass143_0`1.<ExecuteInternal>b__0(Context ctx, CancellationToken ct)
at Polly.RetrySyntax.<>c__DisplayClass12_1.<WaitAndRetry>b__1(Context ctx, CancellationToken ct)
at Polly.Retry.RetryEngine.Implementation[TResult](Func`3 action, Context context, CancellationToken cancellationToken, IEnumerable`1 shouldRetryExceptionPredicates, IEnumerable`1 shouldRetryResultPredicates, Func`1 policyStateFactory)
at Polly.RetrySyntax.<>c__DisplayClass12_0.<WaitAndRetry>b__0(Action`2 action, Context context, CancellationToken cancellationToken)
at Polly.Policy.ExecuteInternal[TResult](Func`3 action, Context context, CancellationToken cancellationToken)
at Polly.Policy.Execute[TResult](Func`3 action, Context context, CancellationToken cancellationToken)
at Polly.Policy.Execute[TResult](Func`1 action)
at Microsoft.Xrm.RemotePlugin.Client.SandboxFabricPlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Xrm.RemotePlugin.Client.ResilientSandboxPlugin.<>c__DisplayClass11_1.<Execute>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.Client.ResilientSandboxPlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.RemotePluginExecute(IServiceProvider serviceProvider, ILifetimeScope lifetimeScope)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Asynchronous.EventOperation.InvokePlugin(AsyncExecutionContext context, IPlugin pluginInstance)
-- End stack trace --

I have the same question (0)
  • Gabriel Barreto Profeta Profile Picture
    15 on at

    Any answers on this subject? I have the same problem.

  • Verified answer
    ZeroHar Profile Picture
    383 on at

    No, actually I ended up writing azure web job.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans