I am currently using the DotSpatial library for .NET (GIS Library). I am getting an error within my AppManager class. The AppManager is a Component that manages the loading of extensions (including data providers), and helps with file serialization:
Code being flagged at foreach
public IEnumerable<string> GetDirectoriesNestedOneLevel()
{
// Visit each directory in Directories Property (usually set by application)
foreach (string directory in Directories.Union(new[] { "Data Extensions", "Tools" }))
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directory);
if (Directory.Exists(path))
{
yield return path;
// Add all of the directories in here, nested one level deep.
var dirs = Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly);
foreach (var dir in dirs)
{
yield return dir;
}
}
}
}
ParamName
first
Source
System.Core
StackTrace
at System.Linq.Enumerable.Union[TSource](IEnumerable
1 first, IEnumerable
1 second) at
DotSpatial.Controls.AppManager.d__9.MoveNext()
in c:\dev\DotSpatial\DotSpatial.Controls\Extensions\AppManager.cs:line
581 at DotSpatial.Controls.AppManager.GetCatalog() in
c:\dev\DotSpatial\DotSpatial.Controls\Extensions\AppManager.cs:line
563 at DotSpatial.Controls.AppManager.LoadExtensions() in
c:\dev\DotSpatial\DotSpatial.Controls\Extensions\AppManager.cs:line
329 at DemoMap.MainForm..ctor() in C:\Users\Logan B.
Lehman\Documents\DemoMap\DemoMap\MainForm.cs:line 230 at
DemoMap.Program.Main() in C:\Users\Logan B.
Lehman\Documents\DemoMap\DemoMap\Program.cs:line 13 at
System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[]
args) at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args) at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()
Any idea on what is going on here? *It would be more than appreciated*
Best Answer
My guess would be that 'Directories' is null. It's not clear from the code snippet where that should be set, but in this case it is not being set. The error is a little cryptic because of the way Union is implemented: it is an extension method, so behind the scenes the actual call is:
Depending on what Directories is, one quick fix would be, before the foreach:
Another possibility would be something like:
But a better fix would be to go to the code that sets directories and make sure it's always setting a value...