Works in Visual Studio 2022 but not in LINQPad
I am attempting to "port" some code from a console app that runs fine in Visual Studio 2022 to LINQPad. An error is thrown in LP when I execute the following:
Application app = New Application();
Package package = app.LoadPackage(packagePath, null);
I am correctly referencing and using the libraries needed for my code:
Microsoft.SqlServer.Dts.Pipeline.Wrapper
Microsoft.SqlServer.Dts.Runtime
The packagePath variable is a fully qualified path to a valid SSIS package that does exist and is not read only.
However, the call to LoadPackage throws the error:
Error: The package failed to load due to error 0x80131534 "(null)". This occurs when CPackage::LoadFromXML fails.
This does not occur when debugging in VS, or running the compiled console application, so I suspect I am missing something. Does anyone have any ideas?
Thanks all.
Comments
AFAIK 0x80131534 isn't a very helpful error as it very generic (sort of like a TypeInitializationException which tells you a C# type did not initialise, but you need to look at the inner exceptions to try to find out why).
So does the stack trace or inner exceptions show anything more?
Unfortunately I don't have any magic solution to diagnose the issue, but some suggestions (based on my own experience where a project failed in LinqPad. It took a while to discover LinqPad was using the wrong dll (which unfortunately for me had the same version number as the correct one !)).
Try to make sure the environments are as similar as possible, e.g. using the same framework version and bitness.
Rather than using nuget packages, add all the dlls from the bin folder from your working project to your LinqPad script.
Check your VS project bin folder for extra files which might be needed like appsettings.json,
Add
Util.Cmd (@"explorer .");
to your script and then compare the dlls there with those in your bin folder. Also look out for sub-folders.Use ProcessExplorer or ProcessMonitor to see what files are being load by both your LinqPad script and your console app.
Failing that add
Debugger.Break();
to your linqpad script and attach VS and disable debug 'just my code' and enable break on first exception and see if that helps pinpoint the error.stackoverflow.com/questions/6604855/how-to-fix-the-error-cpackageloadfromxml-that-causes-the-package-to-fail
Thanks for the response, but those solutions only apply to SSIS projects in Visual Studio, not C# code in LINQPad.