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 6:34pm

But how do you de-serialize?
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 6:37pm

       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 6:44pm

I assume the code breaks at mapping = x.Deserialize(r), right?

When you say not debug mode, where then?

Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 6:46pm

I assume the code breaks at mapping = x.Deserialize(r), right?

When you say not debug mode, where

December 29th, 2011 7:12pm

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).

Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 7:18pm

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 d

December 29th, 2011 7:56pm

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.

Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 8: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

December 29th, 2011 8:30pm

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
Free Windows Admin Tool Kit Click here and download it now
December 29th, 2011 8:45pm

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/receivin
December 30th, 2011 11:43am

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.

Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 2:56pm

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 an

December 30th, 2011 3:49pm

Could be. Let's make this change:

  1. Compile that deserialization code into an external assembly;
  2. Reference this new DLL in the Script Task; and
  3. Retest the package.

I think having such a library as an assembly is anyways a plus (makes it reusable).

Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 4:01pm

Could be. Let's make this change:

  1. Compile that deserialization code into an external assembly;
  2. Reference this new DLL in the Script Task; and
  3. Retest the package.

I think having such a library as an assembly is anyways a plus (makes it reus

December 30th, 2011 4:33pm

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.

 

Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 5:07pm

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.

December 30th, 2011 6:11pm

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.

Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 6:26pm

Getting the same error on the serialize() method.  It sounds like I have a similar setup.  using a VS2008 SSIS script and XMlSerializer.  When I run this package locally or on my dev machine it runs fine.  However, when I deploy the package to my SQL Server 2008 environment it breaks at the serialize() line of code.

Here is where it gets interesting.  I have the EXACT same code and package on a VS2012 SSIS script.  In terms of code it is exactly the same (as I copied it over).  I deployed this VS2012 SSIS package to a SQL Server 2012 box (another server) and it runs just fine there. 

There must be some incompatibility, missing dependency, or maybe the difference is the .NET framework.  3.5 (does not work) versus 4.0 (works).

This is not a solution but maybe a hint that leads to one.

March 13th, 2015 7:10pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics