Deserialization works only in debug mode
When I try to deserialize an XML document (defined via File-Connection) it works fine in debug mode but I get an error in non-debug-mode. What's the problem here?
Error: 2011-12-29 19:31:40.25
Code: 0x00000001
Source: Read data from SAP
Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: There is an error in X
ML document (0, 0). ---> System.TypeInitializationException: The type initializer for 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1' threw an exception
. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1..cctor()
--- End of inner exception stack trace ---
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1..ctor()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract.get_Reader()
at System.Xml.Serialization.TempAssembly.InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
December 29th, 2011 1:43pm
But how do you de-serialize?Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 1:46pm
Using r As New StreamReader(Dts.Connections("mapping.xml").ConnectionString)
Dim l As New List(Of Mapping)
Dim x As New XmlSerializer(l.GetType)
mapping = x.Deserialize(r)
End Using
December 29th, 2011 1:53pm
I assume the code breaks at mapping = x.Deserialize(r), right?
When you say not debug mode, where then?Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 1:55pm
I assume the code breaks at mapping = x.Deserialize(r), right?
When you say not debug mode, where then?
Arthur My Blog
Yes, in deserialize, see the stacktrace in my first posting.
When I run the package without a breakpoint or with Ctrl+F5
December 29th, 2011 2:20pm
So in other words, you are able to deserialize the file and pass through the offending line of code by just not debugging?
And this last line is contrary to what you have said in the beginning (that the package works if you debug).Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 2:27pm
So in other words, you are able to deserialize the file and pass through the offending line of code by just not debugging?
And this last line is contrary to what you have said in the beginning (that the package works if you debug).
Arthur My Blog
The error occurs only when NOT debugging.
December 29th, 2011 3:05pm
OK, so now I am under an impression as follows:
1) You created a Script Task in which you deserialize the XML file used subsequently by a XML source. Then
2) You run the package and it works. However,
3) If you debug it in BIDS [by setting a breakpoint yes/no?] the execution hits this line of code: mapping = x.Deserialize(r) and BIDS displays the error you provided above. Yes or no?
I am asking because what you tell does not make sense to me. It either works or not ever.Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 3:14pm
OK, so now I am under an impression as follows:
1) You created a Script Task in which you deserialize the XML file used subsequently by a XML source. Then
2) You run the package and it works. However,
3) If you debug it in BIDS [by setting a breakpoint yes/no?] the execution hits this line of code: mapping = x.Deserialize(r) and BIDS displays the error you provided above. Yes or no?
I am asking because what you tell does not make sense to me. It either works or not ever.
Arthur My Blog
Puh...
Again: The error occurs
O N L Y when
N O T debugging.
And yes: Seems to make no sense ;)
December 29th, 2011 3:39pm
Ok, thanks. See if this post is applicable: http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/ and potentially this Connect item is applicable: http://connect.microsoft.com/VisualStudio/feedback/details/501190/receiving-...TitleArthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 3:54pm
Ok, thanks. See if this post is applicable: http://blog.fredrikhaglund.se/blog/2009/12/22/debugging-exception-has-been-thrown-by-the-target-of-an-invocation/ and potentially this Connect item is applicable: http://connect.microsoft.com/VisualStudio/feedback/details/501190/receiving-...Title
Arthur My Blog
I think I do not have all these compiler options since a SSIS package gets compiled on the fly?
December 30th, 2011 6:52am
I suggest you test that outside the BIDS, I would create a .net console app to see if the malady repeats itself. This way you will know if this is your machine or SSIS or what is an issue.
As an aside, oftentimes this can be remedied by applying the latest updates.
I suggest you apply the latest service pack to all the products if you are overdue for any one.Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 9:57am
I suggest you test that outside the BIDS, I would create a .net console app to see if the malady repeats itself. This way you will know if this is your machine or SSIS or what is an issue.
As an aside, oftentimes this can be remedied by applying the latest updates.
I suggest you apply the latest service pack to all the products if you are overdue for any one.
Arthur My Blog
Outside of SSIS it works in debug and non-debug mode.
The Class itself in part of a Script Task "Project" in BIDS not of an external assembly. Could this be the reason that the XMLDeserializer cannot work?
December 30th, 2011 10:51am
Could be. Let's make this change:
Compile that deserialization code into an external assembly; Reference this new DLL in the Script Task; and
Retest the package.
I think having such a library as an assembly is anyways a plus (makes it reusable).Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 11:03am
Could be. Let's make this change:
Compile that deserialization code into an external assembly; Reference this new DLL in the Script Task; and
Retest the package.
I think having such a library as an assembly is anyways a plus (makes it reusable).
Arthur My Blog
Hm, this works... strange. Bug?
How will these external assemblies be deployed? To make it work I had to copy the DLL into SQL-Servers binn-directory. Is this manual task always required or is it done somehow by packaging and deployment?
December 30th, 2011 11:34am
Yes, there is a potential for a bug. Thus, feel free to log it in
MS Connect.
You need to deploy it to the GAC, too. I will better point you to a blog post that covers this: http://www.hoekstra.co.uk/index.php/software-mainmenu-36/ssis-mainmenu-75/73-create-and-use-a-c-assembly-for-ssis.html?start=1
I suggest when you go live you create a script that will take care of all, but it is not too too laborious.
Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 12:09pm
Yes, there is a potential for a bug. Thus, feel free to log it in
MS Connect.
You need to deploy it to the GAC, too. I will better point you to a blog post that covers this: http://www.hoekstra.co.uk/index.php/software-mainmenu-36/ssis-mainmenu-75/73-create-and-use-a-c-assembly-for-ssis.html?start=1
I suggest when you go live you create a script that will take care of all, but it is not too too laborious.
Arthur My Blog
Are you 100% sure? Because I can see that SSIS seeks for the dll in ...DTS/binn. So I see no need to pollute the GAC with this dll.
My dll is not deployed into the GAC and when I remove it, it will no longer work. I think it works in DTS/binn because the DTExec.exe is located there?
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\Program Files\Microsoft SQL Server\100\DTS\binn\DTExec.exe.Config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///c:/Program Files/Microsoft SQL Server/100/DTS/binn/ClassLibrary1.DLL.
LOG: Attempting download of new URL file:///c:/Program Files/Microsoft SQL Server/100/DTS/binn/ClassLibrary1/ClassLibrary1.DLL.
LOG: Attempting download of new URL file:///c:/Program Files/Microsoft SQL Server/100/DTS/binn/ClassLibrary1.EXE.
LOG: Attempting download of new URL file:///c:/Program Files/Microsoft SQL Server/100/DTS/binn/ClassLibrary1/ClassLibrary1.EXE.
December 30th, 2011 1:13pm
The steps for the proper deployment are:
Copy the physical .dll file to the target machine's .NET framework directory
Install the assemply to the GAC
If I remember right it looks in binn\DTExec as the last place, you should use CAG - it is designed for these things, so no polluting is involved. I rather would not pollute the Binn directory.Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 1:28pm