"Cannot load dynamically generated serialization assembly." error when executing a clr function that calls a web service in SQL server 2008 R2.
I have a database project in Visual Studio 2017 which includes a clr function that calls a web service.
The project properties include the following:
Project Settings Target Platform = SQL Server 2008
SQLCLR Target framework = .Net Framework 3.5
SQLCLR Build Generate serialization assembly = On
The serialization assembly is created in the database by a post-deployment script when the database is published. When I publish the databse to a SQL Server 2008R2 instance on my Windows 10 PC, executing the clr function results in the "Cannot load dynamically generated serialization assembly" error, however, when the database is published to a SQL2016 instance on my PC, it runs OK
Post deployment script to register serialization assembly:
CREATE ASSEMBLY [CifasEdit.XmlSerializers] FROM 'C:\tfs\CIFAS\Source\Database\Hub\CifasEdit\CifasEdit\bin\Release\CifasEdit.XmlSerializers.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS;
GO
The full error is here
A .NET Framework error occurred during execution of user-defined routine or aggregate "xxx":
System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.
System.IO.FileLoadException:
at System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection)
at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.
...
System.InvalidOperationException:
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()