
I have a plug-in that is deployed with an isolation mode of sandbox. The uses an instance of the OrganizationServiceContext class generated by CrmSvcUtil.exe to perform LINQ queries, e.g. MyOrganizationServiceContextInstance.SystemUserSet.FirstOrDefault(x => x.Id == PluginExecutionContext.UserId) to get the SystemUser running the plug-in. Of course, SystemUserSet is underlyingly CreateQuery<SystemUser>(). I am getting an error "The specified type <MyEarlyBoundNamespace>.SystemUser is not a known entity type." I have added the ProxyTypesAssembly Attribute to the Assembly.cs file. I have seen one or two posts that say you can't execute LINQ queries in this fashion in a sandboxed plugin and one or two posts that say you can. Can someone please confirm (or deny) whether or not it is possible to execute LINQ queries in a sandboxed plug-in?
*This post is locked for comments
I have the same question (0)I am using the new Beta 1 version of the new Developer Toolkit for Dynamics 365 that Microsoft just release on 11-11-2016 and updated on 22-11-2016.
I modified the PluginBase.cs class file and changed the internal LocalPluginContext constructor to include this code. However, there is a problem in instantiating an OrganizationServiceContext class instance and the SystemUser class instance here, causing the exception to be thrown. I therefore moved the code directly into the plugin's Execute method. But there are still problems.
It just looks like there is problems using LINQ with the OrganizationServiceContext in Sandbox Isolation Mode. It would seem as if the CreateQuery<EntityType>() method is executed in a different application domain or a different thread and that domain or thread is not passed the details of the EntityType, in my case SystemUser.
I suspect then that it is not possible to run LINQ in an isolated (sandbox) plug-in. However, I wonder if there is a way to force the LINQ to not be lazy loading and if that will make a difference.
But for now, it would seem to me that it is not possible. It would be great if someone from Microsoft can confirm my findings.