none
ArgumentNullException in GetSemanticModel()

    Вопрос

  • I'm getting a System.ArgumentNullException when I do this:

     

     SemanticModel semanticModel = (SemanticModel)workspace.CurrentSolution.GetProjectByDisplayName(projectName).GetDocument(dID).GetSemanticModel();
    

     

    Strangely, this was working fine this morning, but it is now broken. I haven't changed anything about how I'm getting my dID, workspace, or projectName; both are still giving the correct values.

    The error message says "Value cannot be null. Parameter name: path".

    Here's the stack trace:

     

       at Roslyn.Compilers.AssemblyFileReference..ctor(String path, Boolean snapshot, Boolean embedInteropTypes, String alias, IMetadataDocumentationProvider documentationProvider)

       at Roslyn.Services.MSBuild.AbstractMSBuildLanguageService.<GetMetadataReferences>d__8.MoveNext()

       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

       at Roslyn.Services.MSBuild.MSBuildWorkspace.HostProject.get_InitialMetadataReferences()

       at Roslyn.Services.Host.HostWorkspace.<>c__DisplayClass46.<OnProjectAdded>b__3c()

       at Roslyn.Services.ProjectState.<>c__DisplayClassc.<CreateLazyMetadataReferences>b__a()

       at Roslyn.Utilities.Future`1.get_Value()

       at Roslyn.Services.CompilationTracker.FinalizeCompilation(Solution snapshot, ICompilation compilation, SkeletonReferenceAndProject skeletonReferenceAndVersion, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilationFromScratch(Solution snapshot, State state, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilation(Solution snapshot, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.GetCompilation(Solution snapshot, Boolean lockGate, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.GetMetadataReference(Solution snapshot, ProjectState fromProject, CancellationToken cancellationToken)

       at Roslyn.Services.Solution.GetMetadataReference(ProjectId projectId, ProjectState fromProject, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.<>c__DisplayClass1.<FinalizeCompilation>b__0(ProjectId id)

       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()

       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)

       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

       at Roslyn.Services.CompilationTracker.FinalizeCompilation(Solution snapshot, ICompilation compilation, SkeletonReferenceAndProject skeletonReferenceAndVersion, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilationFromScratch(Solution snapshot, State state, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilation(Solution snapshot, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.GetCompilation(Solution snapshot, Boolean lockGate, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.GetMetadataReference(Solution snapshot, ProjectState fromProject, CancellationToken cancellationToken)

       at Roslyn.Services.Solution.GetMetadataReference(ProjectId projectId, ProjectState fromProject, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.<>c__DisplayClass1.<FinalizeCompilation>b__0(ProjectId id)

       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()

       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)

       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

       at Roslyn.Services.CompilationTracker.FinalizeCompilation(Solution snapshot, ICompilation compilation, SkeletonReferenceAndProject skeletonReferenceAndVersion, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilationFromScratch(Solution snapshot, State state, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.BuildCompilation(Solution snapshot, CancellationToken cancellationToken)

       at Roslyn.Services.CompilationTracker.GetCompilation(Solution snapshot, Boolean lockGate, CancellationToken cancellationToken)

       at Roslyn.Services.Solution.GetCompilation(ProjectId projectId, CancellationToken cancellationToken)

       at Roslyn.Services.Project.GetCompilation(CancellationToken cancellationToken)

       at Roslyn.Services.Document.GetSemanticModel(CancellationToken cancellationToken)

       at FindReferences.FindReferences.findChangedTypes(String baseFile, String changedFile) in C:\Documents and Settings\pbiencourt\Desktop\Projects\FindReferences\FindReferences\Refactored.cs:line 218

     

     

    I'm having some trouble working around/debugging this, any ideas?

     

    EDIT: I can make it work with a small test solution. However, on our large-scale solutions it's failing with the null path exception. I have double checked that all the files it might need  are in the correct locations. Is there a limitation with Roslyn that might explain this behavior?

     


    • Изменено pinieb 9 декабря 2011 г. 20:45 new information
    9 декабря 2011 г. 19:26

Все ответы

  • Possibly something about your project file changed?  There exception is due to a filename that is expected to be part of a project file element is missing.  (Roslyn may be making an incorrect assumption/expectation about the contents of the project file.)
    Wayward LINQ Lacky
    9 декабря 2011 г. 23:52
  • Hi - Any updates about this issue? If you were able to figure out what was causing this and if you think this is a bug in Roslyn could you please log a bug on Connect for this? Alternately, if you can post any additional info that can help us repro this, I can log the bug internally on your behalf.

    The exception is coming from the constructor for 'AssemblyFileReference'. So I would check all the <Reference> tags in the .csproj file to make sure all the .dlls exist. It may also be interesting to check whether the bug is being caused because Roslyn is not processing relative paths correctly for some reason...


    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
    4 января 2012 г. 2:20
  • Hello,

    i have the same issue for every Visual Basic project. With C Sharp projects everything works fine.

    I can simply reproduce the exception by creating an empty VB-Project (only one default class included) and then try to access the MetaDataReferences.

     

    foreach (IProject project in solution.Projects)
    {
         var references = project.MetadataReferences;
    }

     

    Any suggestion?

    21 января 2012 г. 16:25
  • Hi Deguoren - I verified that the code you posted above works fine against latest internal version of the Roslyn APIs. I verified this code against solutions containing both VB and C# projects and printed out the contents of var references above to make sure that the references were correct. So this issue should hopefully be fixed in the next public release of Roslyn.

    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

    • Предложено в качестве ответа Deguoren 9 апреля 2012 г. 16:22
    7 апреля 2012 г. 0:30