I know there are diverse reasons that this error may be thrown but I've found nothing searching SO that seems to be applicable in this case.
I have an SSIS package that fails to build with the error:
Attempt to parse the expression "Replace(@[$Project::RootDirectory] + "\\files\\in",
"\\\\","\\")" failed and returned error code 0xC00470A6.
The expression cannot be parsed.
It might contain invalid elements or it might not be well-formed.
There may also be an out-of-memory error.
However I can open the expression that the build is failing on and click "Evaluate Expression" without any issue. It works just fine.
This is Visual Studio 2017 which the company is using with Production packages so upping the version isn't an option.
I've tried about everything I can think of to alleviate the error but it persists.
Another point I should mention is the subsequent error that follows:
The variable "$Project::RootDirectory" was not found in the Variables collection.
The variable might not exist in the correct scope.
And that this package was exported from the SQL package store for modifications
How can I resolve the error if the build is seemingly attempting to perform the same evaluation behind the scenes and is for some reason having a problem?
And that this package was exported from the SQL package store for modifications
There's your smoking gun. Probably.
Package and Project variables are only valid for Project Deployment Model packages. The SSIS Package Store and various other names imply the legacy Package Deployment Model, usually stored on disk but possibly the msdb.
Assuming you did download the unit of deployment, an .ispac file, that's a self contained project file for SSIS projects. It has a everything needed to recreate the project: a manifest file, the packages, a project.params file, and optionally any project level connection manager(s).
What you're experiencing is the SSIS project that you have opened cannot find a reference to the project parameter $Project::RootDirectory
How you got to this point, is unknown. Resolution is probably dependent on how we got to this point, but I'd start with adding a Project Parameter of RootDirectory
Then your expression will at least parse. This is what it looks like if the value is blank
If that solves things, then it's a matter of getting this deployed back to where it belongs. The project.params file needs to travel the package otherwise, the execution will fail with probably a similar error as the execution engine won't have a reference for the project parameter.