0

I have a script that creates a directory oath based on two variables. I was trying to troubleshoot it when the script suddenly stopped building.

First, there is a read only variable that provides the directory/folder (User::sPriceListSourceFolder). A second grabs the latest price list file (User::sRecentPriceListFile, read/write). The next step in the SSIS sequence is to use this combination to copy a most recent file based on the previously determined directory to another directory. This process was failing for some reason because it wasn't producing the final /, so the directory and file name weren't separated.

I inserted two message boxes, one for each variable, to test what strings were being passed. I kept getting "There is an error, are you sure you want to build?" which I may have accidentally accepted the first time. I went back and commented out the two message boxes to get rid of the error, but I'm still getting the error. I don't know why this suddenly happened. Any suggestions here given my main? The only changes to this are the two commented out lines. Thanks in advance.

public void Main()
    {

        var directory = new DirectoryInfo(Dts.Variables["User::sPriceListSourceFolder"].Value.ToString());
        /// MessageBox.Show(Dts.Variables["User::sPriceListSourceFolder"].Value.ToString());


        FileInfo[] files = directory.GetFiles();
        DateTime lastCreated = DateTime.MinValue;

        foreach (FileInfo file in files)
        {
            if (file.CreationTime > lastCreated)
            {
                lastCreated = file.CreationTime;
                Dts.Variables["User::sRecentPriceListFile"].Value = file.ToString();
            }
        }

        /// MessageBox.Show(Dts.Variables["User::sRecentPriceListFile"].Value.ToString());


        Dts.TaskResult = (int)ScriptResults.Success;
    }

EDIT: I have tried the following: -Restarting the PC -Updating main so it only returns success -Rebuilding and trying to run from within the scripting window.

The final says I have 26 errors?? This is a sample of the output, won't put all 26 here:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ST_4aac98dc09864544a7485d4005384dc9 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets

File name: 'System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ST_4aac98dc09864544a7485d4005384dc9 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets

File name: 'System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\14.0\bin\System.Collections.Immutable.dll' or one of its dependencies. The system cannot find the file specified. ST_4aac98dc09864544a7485d4005384dc9 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets

File name: 'file:///C:\Program Files (x86)\MSBuild\14.0\bin\System.Collections.Immutable.dll' ST_4aac98dc09864544a7485d4005384dc9 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets

at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) ST_4aac98dc09864544a7485d4005384dc9 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets

Not sure what happened here, all I did was add a row for a Message box and then comment it out.

Hadi
  • 36,233
  • 13
  • 65
  • 124
Vaslo
  • 480
  • 1
  • 5
  • 22
  • Not seeing the issue. I even took your code and threw it in a script task and it was fine. Must be somewhere else. What version of Visual Studio are you using? I'm on 2017 and it will show red in the scroll bar to the right on where there is an issue. – Tim Mylott Jul 24 '19 at 15:44
  • Can you use file.FullPath() instead of ToString() to rule out invalid path...However, there are cases where the string returned by the ToString method does not represent the fully qualified path. For example, when you create a FileInfo object using the GetFiles method, the ToString method does not represent the fully qualified path. – Ross Bush Jul 24 '19 at 15:48
  • Is the error related to build/compile or does the script task fail at runtime? – Tim Mylott Jul 24 '19 at 15:51
  • Is the script not building or not executing (completing)? In the project bin folder delete any vhost files. They are locks and will prevent code from executing. – jdweng Jul 24 '19 at 16:09
  • Thanks all for responding! Tim - Using VS2015 so it should be doing what you are saying. The failure is occurring at build compile. I just tried to delete all my code in Main() except for the TaskResult = Success and it still didn't work – Vaslo Jul 24 '19 at 16:53
  • Ross - Your suggestion doesn't fix my build failure, but once that failure goes away I will try what you are suggesting because it may be causing the issue I had in the first place. – Vaslo Jul 24 '19 at 16:58
  • jdweng - I didn't see much of anything in the bin folder in the project director – Vaslo Jul 24 '19 at 17:45
  • wonder if something else was accidentally deleted from the scrip task if deleting all code in Main() except success still gives you the same error. If what you posted is the only code maybe just delete the script task all together and create new. Might take longer trying to troubleshooting what happened then would be recreating. – Tim Mylott Jul 24 '19 at 18:21
  • I tried to create from scratch as well, with and without the code. Even with a blank script I'm getting that error. I'm trying now to see if I can get that Immutable package that it's specifically asking for loaded in, but locked down work PC doesn't allow me many solutions. Just don't know why this suddenly happened. I didn't update VS, SQL Server or anything. – Vaslo Jul 24 '19 at 18:29
  • Check TargetServerVersion from project Properties and check Debugging -> Run64BitRuntime option ... – Khairul Alam Jul 25 '19 at 07:19

1 Answers1

0

I had the exact same issue today. 26 errors when attempting to build; the 26 included all of the errors listed by Vaslo above. The solution is to edit the devenv.exe.config file in C:\Users\[username]\AppData\Local\Microsoft\VisualStudio\14.0. Change the new version of System.Collections.Immutable.dll from 1.1.36.0 to 1.1.37.0 in devenv.exe.config. That fixes it. The project builds successfully after the change.

I got the solution from this blog: https://vinceavery.wordpress.com/ (Search for 'immutable')

Sean
  • 1
  • 1