I am encountering a problem with running stored procs that execute methods within a custom .Net assembly I have built and fully unit tested. In SQL Server 2014 my solution works and the stored proc executes just fine, its only when I use SQL Server 2008 R2 that I get these errors.
The problem is when I add my assembly to SQL Server 2008 R2, create my stored procs, and execute one of them like this:
EXEC dbo.Avatas_CallAddCustomerAndAddCreditCardService 4111111111111111, '1025' , 925 ,
3500, '20/20' , 'asdf' , 1111, 1111 , '600094' , '0442375110' ,
'asdf' , 'asdf' , '01' , NULL , 7777
I get the following error:
Msg 6522, Level 16, State 1, ProcedureAvatas_CallAddCustomerAndAddCreditCardService, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "Avatas_CallAddCustomerAndAddCreditCardService": 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.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.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location, Evidence evidence) at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlRootAttribute root) at FirestreamAvatasCustomerVault.AscendAvatasInt35.AvatasWebServiceCaller.DeserializeAvatasResponse(String response) at FirestreamAvatasCustomerVault.AscendAvatasInt35.AvatasWebServiceCaller.CallManageCustomerService(Int32 personId, String address1, String address2, Int32 cityId, Int32 stateProvId, String zip, String phone, String firstName, String lastName, String company, Nullable1 customerVaultId, Nullable
1 clientId) at FirestreamAvatasCustomerVault.AscendAvatasInt35.AvatasWebServiceCaller.CallAddCusto...
I have changed Generate Serialization Assembly to On and have the XMLSerializers.dll
produced by it registered as well as the actual dll registered.
Here is my stored procedure and assembly creates:
CREATE ASSEMBLY [Avatas]
AUTHORIZATION [dbo]
FROM 'D:\TFS Workspace\Firestream\Dev\AvatasCustomerVault\FirestreamAvatasCustomerVault\FirestreamAvatasCustomerVault.AscendAvatasInt35\bin\.Net 3.5'
WITH PERMISSION_SET = UNSAFE
CREATE ASSEMBLY [Avatas.XmlSerializers]
AUTHORIZATION [dbo]
FROM 'D:\TFS Workspace\Firestream\Dev\AvatasCustomerVault\FirestreamAvatasCustomerVault\FirestreamAvatasCustomerVault.AscendAvatasInt35\bin\.Net 3.5\FirestreamAvatasCustomerVault.AscendAvatasInt35.XmlSerializers.dll'
WITH PERMISSION_SET = UNSAFE
exec('CREATE PROCEDURE [dbo].[Avatas_CallAddCustomerAndAddCreditCardService](@creditCardNumber bigint, @expirationDate nvarchar(10), @ccv int,
@personId int, @address1 nvarchar(100), @address2 nvarchar(100),
@cityId int,
@stateProvId int, @zip nvarchar(50), @phone nvarchar(20), @firstName nvarchar(150), @lastName nvarchar(150), @company nvarchar(150), @customerVaultId int, @clientId int)
AS EXTERNAL NAME [Avatas].[FirestreamAvatasCustomerVault.AscendAvatasInt35.AvatasWebServiceCaller].[CallAddCustomerAndAddCreditCardService]')
The actual line that the error occurs on is as follows:
XmlSerializer serializer = new XmlSerializer(typeof(AvatasResponse), xRoot);