Convert (signed, VB) CLR UDT to XML  
Author Message
sdrobinson





PostPosted: Sun Aug 26 18:50:00 CDT 2007 Top

SQL Server Developer >> Convert (signed, VB) CLR UDT to XML

Hi,
I'm getting the 'cannot load dynamically generated assemblies' error when
trying to convert a CLR UDT to XML. The UDT is written in VB and is signed
with a strong name key (neither of which _should_ be relevant !).
I have followed the steps in: http://www.hide-link.com/
as possible, however this is C# specific (Ggrrrrr!).
Although I cannot get sgen working through Build tasks (Grrr - justs exits
with Code 1) I can manually run it using the /keep option, and then manually
compile the temporary C# code file and sign it with the same strong name key
(so much for Rapid Application Development!).
(For some reason the build setting Generate Serrialization Assemblies has
absolutely no effect in my environment - On and Auto produce exactly the same
output as Off - e.g. none - Grrr).
I can then use pre/post deployment scripts to deploy the serializers dll
with my UDT dll.
Which is all very well, (if a total pain in the a$%E), except it still
doesn't work (gggrrr!).
Both dll's are registered in SQL, both are signed, both have the same
version, and the UDT works exactly as expected, except when I try to
CAST(myUDT as xml), when it all falls to pieces - gggrrrrr.
I read on Steven Hemingway's blog
http://www.hide-link.com/
that the above workaround as mentioned in Vineet Rao's blog
http://www.hide-link.com/
work, and he's planning on publishing some working workarounds in future
posts.
In the meantime, I don't suppose anyone here has managed to get a signed, VB
UDT that implements custom xml serialization using IXmlSerailizable working
in SQL ??? Or am I destined to keep banging my head against the wall and
growling ? :)
thanks in advance,
justafrustratedgeezer
Paul Bryant

SQL Server134  
 
 
justageezer





PostPosted: Sun Aug 26 18:50:00 CDT 2007 Top

SQL Server Developer >> Convert (signed, VB) CLR UDT to XML Well, I managed to figure it out in the end :)
All I needed (!) was to call sgen /keep and then csc from a post-build batch
file, and use the pre- and post-deployment scripts from Vineet's blog post.
The batch file (stored in the /bin folder) looks like:
<pre>
@ECHO OFF
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /a:%1.dll
/n /s /force /keep
IF EXIST source.cs DEL source.cs
IF EXIST *.out DEL *.out
IF EXIST *.tmp DEL *.tmp
IF EXIST *.cmdline DEL *.cmdline
IF EXIST *.err DEL *.err
IF EXIST *.Deleted DEL *.Deleted
IF EXIST *.cs REN *.cs source.cs
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe
/out:%1.XmlSerializers.dll /r:%1.dll /nologo /keyfile:..\snKey.snk /t:library
/debug- /optimize+ /utf8output source.cs
DEL source.cs
IF ERRORLEVEL 1 GOTO END
:END
</pre>
and you have to pass it the qualified name of the assembly as it's only
argument e.g.:
call "$(TargetDir)postbuild.bat" $(TargetName)

Without the build task you have to manually keep both dll's synched - if you
make any changes to the main dll the serializer has to be re-created,
re-signed and re-deployed, even if all you did was change a comment, or you
get the 'cannot load dynamically generated...' error.

Hth,
Paul




> Hi,
> I'm getting the 'cannot load dynamically generated assemblies' error when
> trying to convert a CLR UDT to XML. The UDT is written in VB and is signed
> with a strong name key (neither of which _should_ be relevant !).
> I have followed the steps in: http://support.microsoft.com/kb/913668 as far
> as possible, however this is C# specific (Ggrrrrr!).
> Although I cannot get sgen working through Build tasks (Grrr - justs exits
> with Code 1) I can manually run it using the /keep option, and then manually
> compile the temporary C# code file and sign it with the same strong name key
> (so much for Rapid Application Development!).
> (For some reason the build setting Generate Serrialization Assemblies has
> absolutely no effect in my environment - On and Auto produce exactly the same
> output as Off - e.g. none - Grrr).
> I can then use pre/post deployment scripts to deploy the serializers dll
> with my UDT dll.
> Which is all very well, (if a total pain in the a$%E), except it still
> doesn't work (gggrrr!).
> Both dll's are registered in SQL, both are signed, both have the same
> version, and the UDT works exactly as expected, except when I try to
> CAST(myUDT as xml), when it all falls to pieces - gggrrrrr.
> I read on Steven Hemingway's blog
> http://blogs.msdn.com/sqlclr/archive/2006/10/18/dynamic-assembly-loading.aspx
> that the above workaround as mentioned in Vineet Rao's blog
> http://blogs.msdn.com/sqlclr/archive/2005/07/25/Vineet.aspx does not always
> work, and he's planning on publishing some working workarounds in future
> posts.
> In the meantime, I don't suppose anyone here has managed to get a signed, VB
> UDT that implements custom xml serialization using IXmlSerailizable working
> in SQL ??? Or am I destined to keep banging my head against the wall and
> growling ? :)
> thanks in advance,
> justafrustratedgeezer
> Paul Bryant