This line of code has been working for a couple years now. But I am having some recent issues with users with creating a blank project. This only happens on some machines and not others. Wonder if anyone might have better insight into error log. I have made sure all of the paths are valid and the user has write permissions.
var cps = new CreateProjectSettings()
{
Name = defaultName,
LocationPath = DefaultFolder(),
TemplatePath = GetDefaultMapTemplate(),
CreateNewProjectFolder = true
};
ProMapBlackLogWriter.Log.Debug("NewBlankProject - CreateAsync");
var newProject = await Project.CreateAsync(cps); //This Fails with log. And has not happened before.
Message = ProjectService::UnpackProjectPackage Failed
Log happens at var newProject = await Project.CreateAsync(cps);
Stack Trace = at ArcGIS.Desktop.Core.CoreModule.<InternalCreateProjectAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ArcGIS.Desktop.Core.Project.<CreateAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at <CreateAsync>d__3.MoveNext() in code.cs:line 353
Oct 06 09:25:26 2022 ERROR - Message = ProjectService::UnpackProjectPackage Failed
It appears that UnpackProjectPackage is failing. Once a template is chosen, ArcGIS Pro is trying to 'unzip' the new ArcGIS Pro project file (from the template) in the destination location path. In order to determine what went wrong you should log both defaultName and DefaultFolder() when CreateAsync fails. And we need the value for GetDefaultMapTemplate() too in order to see if the template file exists.
I am trying to duplicate this issue, what version of Pro are you using?
I am using pro 2.5.0 still as that is what our configuration program was built on. The Names and folder paths all seem fine. The user can write to all of those locations too. On my computer the code works, which is what makes this difficult.
Here is the logging from that part of the code that we added to see and test the paths. The OneDrive path works on my computer, as we thought that might have been it, but it wasn't.
DEBUG NewBlankProject - defaultName - ADA1_2022_3_010_TEST
DEBUG NewBlankProject - defaultFolder - C:\Users\USERNAME\OneDrive - Corteva\Documents\ArcGIS\Projects
DEBUG NewBlankProject - templatePath - C:\Program Files\ArcGIS\Pro\Resources\ProjectTemplates\Map.aptx
There is one issue i ran into while testing this. Apparently the given 'LocationPath' has to exist otherwise Pro will use the default project path. You could change your code snippet a bit to prevent this problem:
var cps = new CreateProjectSettings()
{
Name = defaultName,
LocationPath = DefaultFolder(),
TemplatePath = GetDefaultMapTemplate(),
CreateNewProjectFolder = true
};
if (!System.IO.Directory.Exists(cps.LocationPath))
System.IO.Directory.CreateDirectory(cps.LocationPath);
//ProMapBlackLogWriter.Log.Debug("NewBlankProject - CreateAsync");
var newProject = await Project.CreateAsync(cps); //This Fails with log. And has not happened before
We just tried that and it still failed. The directory already exists.
Stack Trace = at ArcGIS.Desktop.Core.CoreModule.<InternalCreateProjectAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ArcGIS.Desktop.Core.Project.<CreateAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at <NewBlankProject>d__3.MoveNext() in ViewModel.cs:line 373
NewBlankProject - Message = ProjectService::UnpackProjectPackage Failed
I will try with 2.5 and use your path values. It looks like you are setting locationpath to the default project location. On those machines where this doesn't work you can create a new project (using any template) from within Pro?
So the user could use the OOB template in pro and create a map project. I used the same name of the file and location. So they have all permissions and files. Nothing seems to be corrupt. Running out of ideas.