我遇到运行存储过程的问题,该存储过程在我自己构建并完全单元测试的自定义.Net程序集中执行方法。在SQL Server 2014中,我的解决方案正常工作,存储过程执行得很好,只有当我使用SQL Server 2008 R2时才会出现这些错误。
问题是当我将程序集添加到SQL Server 2008 R2时,创建我的存储过程并执行其中一个如下:
EXEC dbo.Avatas_CallAddCustomerAndAddCreditCardService 4111111111111111, '1025' , 925 ,
3500, '20/20' , 'asdf' , 1111, 1111 , '600094' , '0442375110' ,
'asdf' , 'asdf' , '01' , NULL , 7777
我收到以下错误:
Msg 6522,Level 16,State 1,ProcedureAvatas_CallAddCustomerAndAddCreditCardService,Line 0 执行用户定义的例程或聚合“Avatas_CallAddCustomerAndAddCreditCardService”期间发生.NET Framework错误: System.InvalidOperationException:无法加载动态生成 序列化装配。在某些托管环境中组装加载 功能受限,请考虑使用预生成的序列化程序。 有关详细信息,请参阅内部异常。
System.IO.FileLoadException:LoadFrom(),LoadFile(),Load(byte [])和 LoadModule()已被主机禁用。
System.InvalidOperationException:
在System.Xml.Serialization.Compiler.Compile(Assembly parent,String ns, XmlSerializerCompilerParameters xmlParameters,证据证据)
在System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping [] xmlMappings,Type [] types,String defaultNamespace,Evidence evidence, XmlSerializerCompilerParameters参数,Assembly assembly, Hashtable程序集) System.Xml.Serialization.TempAssembly..ctor(XmlMapping [] xmlMappings, 键入[]类型,字符串defaultNamespace,字符串位置,证据 证据) System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping,Type type,String defaultNamespace,String location, 证据证据) System.Xml.Serialization.XmlSerializer..ctor(类型类型, XmlAttributeOverrides覆盖,Type [] extraTypes,XmlRootAttribute root,String defaultNamespace,String location,Evidence evidence)
在System.Xml.Serialization.XmlSerializer..ctor(类型类型, XmlRootAttribute root)at FirestreamAvatasCustomerVault.AscendAvatasInt35.AvatasWebServiceCaller.DeserializeAvatasResponse(字符串 回应) 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 ...
我已将Generate Serialization Assembly更改为On并使其生成的XMLSerializers.dll
已注册,并且已注册实际的dll。
这是我的存储过程和程序集创建:
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]')
发生错误的实际行如下:
XmlSerializer serializer = new XmlSerializer(typeof(AvatasResponse), xRoot);
答案 0 :(得分:0)
我发现的最终解决方案是SQL Server 2008和2008 R2仅支持编译到.Net Framework 3.5版本的dll。而SQL Server 2012+仅支持版本4及更高版本。