I was tasked with writing a CLR function that would mass send emails using Mandrill.Net. After a lot of hurdle with assemblies and other issues I managed to patch most of the function. The only thing left was to add sending those emails (I already had code for that). Unfortunately after I added the code I got this error:
Dynamic operations can only be performed in homogenous AppDomain
As it turns out Mandrill.Net (and RestSharp which is used under the hood) makes extensive use of dynamic types. Obviously I did search for solutions for this problem and most of what I found looked like this:
<NetFx40_LegacySecurityPolicy enabled="true"/>
<trust legacyCasModel="false" level="Full" />
That is adding those two lines to the config file of the project. I applied the solution to the app.config
file, but nothing changed and I still get the error (yes, I recreated the assembly and function in Sql Server).
Truth to be told I couldn't find anything about this problem in the Sql Server CLR context, so it occurred to me that that it might actually be impossible to use those types in that context (like SQL Server is in control of the policy that prevents the use of dynamic types and not my own library). Can those dynamic types actually be used in CLR functions in SQL Server?
P.S. In my code I'm also using Dapper. In an earlier stage I also got this error when I explicitly used dynamic
type to store results of a query (in fact Dapper returns those as IEnumerable<dynamic>
). However after adding a Linq Cast<Dictionary<string,object>>()
the error went away (though Dapper was still likely operating on the dynamic
type).