2

I've kicked my head with this one for several days now. I've done a lot of research and have found issues closely related but not specific to my case.

Working on a Visual Studio 2008 SSIS package. Using only one scripting component. In this scripting component, I am serializing a stongly typed class (CCMSModel) and trying to write it out to the server's d:\ drive. I am using .NET 3.5. Works just fine on my development machine but breaks when I deploy it to my SQL Server 2008 R2 (SSIS). I've completely trimmed down my code to remove any added complexity:

[Serializable]
public class CCMSModel
{
    public string BOBorEOB { get; set; }
}

...

List<CCMSModel> myList = new List<CCMSModel>();
CCMSModel item = new CCMSModel();
item.BOBorEOB = "Test";
myList.Add(item);

string filePath = "d:\\ScheduleFiles\\6xml\\ss.xml";
var serializer = new XmlSerializer(typeof(List<CCMSModel>));
using (var stream = File.OpenWrite(filePath))
{
    serializer.Serialize(stream, myList);
}

...

Want to add that I have sufficient rights to write on the server and I am a sysadmin on the sql server. I also have an another SSIS package using Visual Studio 2012 (SSIS) with .NET 4.0 and deploying to SQL Server 2012. This package is EXACTLY the same (did a copy / paste of the code) and it works just fine.

In my research I found an article that I couldn't help but to see a very close relationship to. Same error and same code. However, this particular scenario is using .NET 4.0 and is deploying or executing in an environment that has .NET 4.0 and 4.5. The article contains a link (at the bottom) claiming to solve the problem (specific to the 4.0/4.5 framework). Claims that the XMLSerialize, in 4.5, is a bit different from the one that runs on my C# compiler hence the incompatibility.

InvalidProgramException with XmlSerializer

Although the article present a close resemblance, this isn't specifically my set up (since I am on 3.5). However, it does allude to the fact that I may be experiencing some incompatiblity with the XMLSerialise implementation. I've hunted down to see if this was the case but I've run dry on my search.

I get an this inner exception error: System.TypeInitializationException: The type initializer for 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterList1' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterList1..cctor()

Community
  • 1
  • 1
crent
  • 21
  • 1
  • What is the OS of the server? Is it possible that it does not have the 3.5 framework installed? What error is generated if you bone the value for `filePath`? – billinkc Mar 19 '15 at 02:03
  • @billinkc: The SQL Server 2008 is on Windows 2008 R2 Enterprise. Yes it has Framework 2.0.50727, 3.0, 3.5 and 4.0 installed. Not sure what you mean by "bone the value for filePath". What I can say though is that this will work if my List was type string: List myList = new List(); myList.Add("1"); myList.Add("2"); myList.Add("3"); However, anytime I introduce a custom class (which I obviously need and required here) then I get that error message. – crent Mar 19 '15 at 16:39
  • I've tried deploying this on 3 different SQL Server 2008 machines. Same exact error and same exact behavior.. I don't think it is my set up. I think there may be a compatibility issue going on here. – crent Mar 19 '15 at 16:39
  • I was curious what error was would look like for non existent directory or lack of permissions (System.IO.DirectoryNotFoundException for the former). I created a Script Task in 2008 and then a standalone console app. I get the same exception as you but mine fails on my development machine as well. – billinkc Mar 19 '15 at 17:32
  • I wonder if there's some COM thing in the dtexec call that is causing this to go sideways. I assume the same error would present if you used the SSIS Api to start the package as well. Too slammed today to try test that route. Doubt it would be any different but worth a shot – billinkc Mar 19 '15 at 17:50
  • I am guessing if it were the dtexec I would see an error for my working sample that uses List (per my comment above). In this case, the error comes from a custom class like CCMSModel. If you get a chance look at the solution I found for .NET 4.5. I posted a link there. It's almost identical with my issue. They found an incompatibility from the XMLSerialize() implementation. . – crent Mar 19 '15 at 19:21

0 Answers0