Namespace not defined issues with project created by VS #132

Open
csmager opened this Issue Aug 12, 2016 · 16 comments

Comments

Projects
None yet
8 participants
@csmager

csmager commented Aug 12, 2016

I'm not sure if I'm being dumb here, but I can't get this to work. I first tried opening a larger project that references other 3rd party dlls that had similar issues in using types from there, but I've managed to recreate with something very minimal. I've pushed the repro here, but for completeness the steps I followed were:

  1. Create new project in VS 2015 (F# Class Lib, .NET 4.6)
  2. Add some simple code that uses System.Text.RegularExpressions. This compiles fine.
  3. Open folder in VS Code with Ionide.

I get these errors:

image

If I create the same project via VS Code using 'F# New Project (without FAKE)', I get no errors. For what it's worth, I tried this in Atom too and had the same issues.

I've tried manually editing the .fsproj file to match the one created by Ionide (using FSharp.Core.dll from Paket was the main change), but didn't have any success.

@csmager

This comment has been minimized.

Show comment
Hide comment
@csmager

csmager Aug 12, 2016

After a bit more fiddling, it appears the offending issue is the import of MIcrosoft.FSharp.Targets.

This, created by VS Code, works:

<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />

This, created by VS 2015, doesn't:

<Import Project="$(FSharpTargetsPath)" />

I'm guessing this is only needed at compile time and, without the condition, ionide is choking on it.

csmager commented Aug 12, 2016

After a bit more fiddling, it appears the offending issue is the import of MIcrosoft.FSharp.Targets.

This, created by VS Code, works:

<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />

This, created by VS 2015, doesn't:

<Import Project="$(FSharpTargetsPath)" />

I'm guessing this is only needed at compile time and, without the condition, ionide is choking on it.

@cloudRoutine

This comment has been minimized.

Show comment
Hide comment
@cloudRoutine

cloudRoutine Aug 12, 2016

Member

Can't reproduce using your ionide-error-repro repo

When diagnosing an issue you're having with ionide turn on this setting

and check the developer log for the errors that are produced

Member

cloudRoutine commented Aug 12, 2016

Can't reproduce using your ionide-error-repro repo

When diagnosing an issue you're having with ionide turn on this setting

and check the developer log for the errors that are produced

@csmager

This comment has been minimized.

Show comment
Hide comment
@csmager

csmager Aug 12, 2016

This seems to be the relevant bits. I assume the conditions to set FSharpTargetsPath aren't met, so the path is empty:

[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/project project Object {Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj", Files: Array[0], Output: "null", References: Array[1], Logs: Object}Files: Array[0]Logs: Objectc:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj: "Microsoft.Build.Exceptions.InvalidProjectFileException: The value "" of the "Project" attribute in element is invalid. Parameter "path" cannot have zero length.
↵ at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
↵ at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject(Boolean condition, String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object arg0, Object arg1, Object arg2, Object arg3)
↵ at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, String importExpressionEscaped, ProjectImportElement importElement) ↵ at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
↵ at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) ↵ at Microsoft.Build.Evaluation.Evaluator4.Evaluate()
↵ at Microsoft.Build.Evaluation.Evaluator4.Evaluate(IEvaluatorData4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary1 environmentProperties, ILoggingService loggingService, IItemFactory2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
↵ at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation)
↵ at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) ↵ at Microsoft.Build.Evaluation.Project..ctor(XmlReader xmlReader, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.projectInstanceFromFullPath@139(FSharpProjectFileInfo this, ProjectCollection engine, String fsprojFullPath)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.FSharpProjectFileInfo.CrackProjectUsingNewBuildAPI(String fsprojFile)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.FSharpProjectFileInfo..ctor(String fsprojFileName, FSharpOption1 properties, FSharpOption1 enableLogging)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.getOptions@376(Boolean enableLogging, FSharpList1 properties, String file) ↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.getOptions(String file, Boolean enableLogging, FSharpList1 properties)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.main(String[] argv)"proto: ObjectOutput: "null"Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"References: Array[1]proto: Object
[Extension Host] [IONIDE-FSAC-REQ] 0 http://localhost:8263/project Object {FileName: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"}
[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/project project Object {Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj", Files: Array[0], Output: "null", References: Array[1], Logs: Object}Files: Array[0]length: 0__proto__: Array[0]Logs: ObjectOutput: "null"Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"References: Array[1]0: "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll"length: 1__proto__: Array[0]concat: concat()constructor: Array()copyWithin: copyWithin()entries: entries()every: every()fill: fill()filter: filter()find: find()findIndex: findIndex()forEach: forEach()includes: includes()indexOf: indexOf()join: join()keys: keys()lastIndexOf: lastIndexOf()length: 0map: map()pop: pop()push: push()reduce: reduce()reduceRight: reduceRight()reverse: reverse()shift: shift()slice: slice()some: some()sort: sort()splice: splice()toLocaleString: toLocaleString()toString: toString()unshift: unshift()Symbol(Symbol.iterator): values()Symbol(Symbol.unscopables): Object__proto__: Object__proto__: Object__defineGetter__: defineGetter()defineSetter: defineSetter()lookupGetter: lookupGetter()lookupSetter: lookupSetter()constructor: Object()hasOwnProperty: hasOwnProperty()isPrototypeOf: isPrototypeOf()propertyIsEnumerable: propertyIsEnumerable()toLocaleString: toLocaleString()toString: toString()valueOf: valueOf()get proto: get proto()set proto: set proto()
[Extension Host] [IONIDE-FSAC-REQ] 0 http://localhost:8263/parse Object {FileName: "c:\dev\FSharpTest\FSharpTest\TextUtil.fs", IsAsync: true, Lines: Array[9]}
[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/parse errors [Object, Object]0: ObjectEndColumn: 36EndLine: 3FileName: "c:\dev\FSharpTest\FSharpTest\TextUtil.fs"Message: "The namespace 'RegularExpressions' is not defined"Severity: "Error"StartColumn: 18StartLine: 3Subcategory: "typecheck"proto: Object1: Objectlength: 2__proto__: Array[0]

csmager commented Aug 12, 2016

This seems to be the relevant bits. I assume the conditions to set FSharpTargetsPath aren't met, so the path is empty:

[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/project project Object {Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj", Files: Array[0], Output: "null", References: Array[1], Logs: Object}Files: Array[0]Logs: Objectc:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj: "Microsoft.Build.Exceptions.InvalidProjectFileException: The value "" of the "Project" attribute in element is invalid. Parameter "path" cannot have zero length.
↵ at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
↵ at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject(Boolean condition, String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object arg0, Object arg1, Object arg2, Object arg3)
↵ at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, String importExpressionEscaped, ProjectImportElement importElement) ↵ at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
↵ at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) ↵ at Microsoft.Build.Evaluation.Evaluator4.Evaluate()
↵ at Microsoft.Build.Evaluation.Evaluator4.Evaluate(IEvaluatorData4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary1 environmentProperties, ILoggingService loggingService, IItemFactory2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
↵ at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation)
↵ at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) ↵ at Microsoft.Build.Evaluation.Project..ctor(XmlReader xmlReader, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.projectInstanceFromFullPath@139(FSharpProjectFileInfo this, ProjectCollection engine, String fsprojFullPath)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.FSharpProjectFileInfo.CrackProjectUsingNewBuildAPI(String fsprojFile)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.FSharpProjectFileInfo..ctor(String fsprojFileName, FSharpOption1 properties, FSharpOption1 enableLogging)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.getOptions@376(Boolean enableLogging, FSharpList1 properties, String file) ↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.getOptions(String file, Boolean enableLogging, FSharpList1 properties)
↵ at Microsoft.FSharp.Compiler.SourceCodeServices.ProjectCrackerTool.Program.main(String[] argv)"proto: ObjectOutput: "null"Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"References: Array[1]proto: Object
[Extension Host] [IONIDE-FSAC-REQ] 0 http://localhost:8263/project Object {FileName: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"}
[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/project project Object {Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj", Files: Array[0], Output: "null", References: Array[1], Logs: Object}Files: Array[0]length: 0__proto__: Array[0]Logs: ObjectOutput: "null"Project: "c:\dev\FSharpTest\FSharpTest\FSharpTest.fsproj"References: Array[1]0: "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll"length: 1__proto__: Array[0]concat: concat()constructor: Array()copyWithin: copyWithin()entries: entries()every: every()fill: fill()filter: filter()find: find()findIndex: findIndex()forEach: forEach()includes: includes()indexOf: indexOf()join: join()keys: keys()lastIndexOf: lastIndexOf()length: 0map: map()pop: pop()push: push()reduce: reduce()reduceRight: reduceRight()reverse: reverse()shift: shift()slice: slice()some: some()sort: sort()splice: splice()toLocaleString: toLocaleString()toString: toString()unshift: unshift()Symbol(Symbol.iterator): values()Symbol(Symbol.unscopables): Object__proto__: Object__proto__: Object__defineGetter__: defineGetter()defineSetter: defineSetter()lookupGetter: lookupGetter()lookupSetter: lookupSetter()constructor: Object()hasOwnProperty: hasOwnProperty()isPrototypeOf: isPrototypeOf()propertyIsEnumerable: propertyIsEnumerable()toLocaleString: toLocaleString()toString: toString()valueOf: valueOf()get proto: get proto()set proto: set proto()
[Extension Host] [IONIDE-FSAC-REQ] 0 http://localhost:8263/parse Object {FileName: "c:\dev\FSharpTest\FSharpTest\TextUtil.fs", IsAsync: true, Lines: Array[9]}
[Extension Host] [IONIDE-FSAC-RES] 0 http://localhost:8263/parse errors [Object, Object]0: ObjectEndColumn: 36EndLine: 3FileName: "c:\dev\FSharpTest\FSharpTest\TextUtil.fs"Message: "The namespace 'RegularExpressions' is not defined"Severity: "Error"StartColumn: 18StartLine: 3Subcategory: "typecheck"proto: Object1: Objectlength: 2__proto__: Array[0]

@csmager

This comment has been minimized.

Show comment
Hide comment
@csmager

csmager Aug 12, 2016

Some further info. If I changed the import to what $(FSharpTargetsPath) should be set to::

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />

I get this error:

"Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\FSharp\Microsoft.FSharp.Targets" was not found.

So that's the cause - that path really doesn't exist as I don't have VS 2013 installed. The $(VisualStudioVersion) should be set to 14.0.

It looks like an issue in ProjectCrackerTool, which it seems that this pull request fixed and was included in the 2.0.0.3 release. As it's not versioned, I quickly decompiled and it looks like the fix is in the version with ionide-fsharp - can you confirm?

csmager commented Aug 12, 2016

Some further info. If I changed the import to what $(FSharpTargetsPath) should be set to::

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets" />

I get this error:

"Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\FSharp\Microsoft.FSharp.Targets" was not found.

So that's the cause - that path really doesn't exist as I don't have VS 2013 installed. The $(VisualStudioVersion) should be set to 14.0.

It looks like an issue in ProjectCrackerTool, which it seems that this pull request fixed and was included in the 2.0.0.3 release. As it's not versioned, I quickly decompiled and it looks like the fix is in the version with ionide-fsharp - can you confirm?

@csmager

This comment has been minimized.

Show comment
Hide comment
@csmager

csmager Aug 12, 2016

After some tracking down, there are issues raised against this on FCS and FSAC resulting in this pull request that will fix the issue (you can follow the links from there back to the original issues).

Although the previous PR I linked to seemed to fix the issue, the exception here occurs at engine.LoadProject which currently happens before the VisualStudioVersion property is set to 14.0.

I suppose this will be fixed as and when that's merged and released.

csmager commented Aug 12, 2016

After some tracking down, there are issues raised against this on FCS and FSAC resulting in this pull request that will fix the issue (you can follow the links from there back to the original issues).

Although the previous PR I linked to seemed to fix the issue, the exception here occurs at engine.LoadProject which currently happens before the VisualStudioVersion property is set to 14.0.

I suppose this will be fixed as and when that's merged and released.

@cloudRoutine cloudRoutine referenced this issue in fsharp/FSharp.Compiler.Service Aug 12, 2016

Closed

Project Cracker Output and Behavior Issues #624

@cloudRoutine

This comment has been minimized.

Show comment
Hide comment
@cloudRoutine

cloudRoutine Aug 12, 2016

Member

@csmager great job tracking that down, I'm going to keep nudging them to pick up the pace on that one.

Member

cloudRoutine commented Aug 12, 2016

@csmager great job tracking that down, I'm going to keep nudging them to pick up the pace on that one.

@Krzysztof-Cieslak

This comment has been minimized.

Show comment
Hide comment
@Krzysztof-Cieslak

Krzysztof-Cieslak Aug 18, 2016

Member

Is there any progress with that on FCS side?

Member

Krzysztof-Cieslak commented Aug 18, 2016

Is there any progress with that on FCS side?

@blumu

This comment has been minimized.

Show comment
Hide comment
@blumu

blumu Nov 15, 2016

@Krzysztof-Cieslak Would it make sense to keep the bug open to keep track of the issue? Even if the root cause is in FCS it's still a bug that surfaces when using Ionide-Vscode. Also, the next person who hits the issue may end up reopening a new bug for it.

blumu commented Nov 15, 2016

@Krzysztof-Cieslak Would it make sense to keep the bug open to keep track of the issue? Even if the root cause is in FCS it's still a bug that surfaces when using Ionide-Vscode. Also, the next person who hits the issue may end up reopening a new bug for it.

@Krzysztof-Cieslak

This comment has been minimized.

Show comment
Hide comment
@Krzysztof-Cieslak

Krzysztof-Cieslak Nov 15, 2016

Member

@blumu I think it should be fixed in latest release of FCS (changes in MsBuild dependency). At least I haven't seen this bug in quite some time.

I'm happy to reopen it if someone still experience it.

Member

Krzysztof-Cieslak commented Nov 15, 2016

@blumu I think it should be fixed in latest release of FCS (changes in MsBuild dependency). At least I haven't seen this bug in quite some time.

I'm happy to reopen it if someone still experience it.

@blumu

This comment has been minimized.

Show comment
Hide comment
@blumu

blumu Nov 17, 2016

@Krzysztof-Cieslak I'm still getting the error on Ionide-fsharp 2.9.4:
image

blumu commented Nov 17, 2016

@Krzysztof-Cieslak I'm still getting the error on Ionide-fsharp 2.9.4:
image

@arcticcacti

This comment has been minimized.

Show comment
Hide comment
@arcticcacti

arcticcacti Feb 27, 2017

I'm not sure if this is exactly the same issue, but I'm getting something similar with Ionide 2.23.5 - in VS Code I do New Project (windows) and get this
image

Building also spits out the error FS0039: The namespace 'ViewModule' is not defined messages

Paket's pulled in the FSharp.ViewModule.Core package and everything seems ok, but I'm not too familiar with the whole dependency system. Sorry if this is in the wrong place!

I'm not sure if this is exactly the same issue, but I'm getting something similar with Ionide 2.23.5 - in VS Code I do New Project (windows) and get this
image

Building also spits out the error FS0039: The namespace 'ViewModule' is not defined messages

Paket's pulled in the FSharp.ViewModule.Core package and everything seems ok, but I'm not too familiar with the whole dependency system. Sorry if this is in the wrong place!

@Krzysztof-Cieslak

This comment has been minimized.

Show comment
Hide comment
@Krzysztof-Cieslak

Krzysztof-Cieslak Aug 27, 2017

Member

Closing due to lack of new reports. Hopefully it's fixed.

Member

Krzysztof-Cieslak commented Aug 27, 2017

Closing due to lack of new reports. Hopefully it's fixed.

@serialhex

This comment has been minimized.

Show comment
Hide comment
@serialhex

serialhex Aug 29, 2017

Doing a New Project (windows) gives me the same error.

Simply changing the line open FSharp.ViewModule -> open ViewModule and the same for open FSharp.ViewModule.Validation fixes the error.

I'm not sure why that is, but it works, and builds the default project just fine now.

Doing a New Project (windows) gives me the same error.

Simply changing the line open FSharp.ViewModule -> open ViewModule and the same for open FSharp.ViewModule.Validation fixes the error.

I'm not sure why that is, but it works, and builds the default project just fine now.

@blumu

This comment has been minimized.

Show comment
Hide comment
@blumu

blumu Aug 31, 2017

@Krzysztof-Cieslak Nothing changed since my last comment so I did not bother reporting the same issue again but I confirm that this is still broken.

blumu commented Aug 31, 2017

@Krzysztof-Cieslak Nothing changed since my last comment so I did not bother reporting the same issue again but I confirm that this is still broken.

@cmeeren

This comment has been minimized.

Show comment
Hide comment
@cmeeren

cmeeren Oct 19, 2017

I'm experiencing a similar error as OP with successful workaround as in #132 (comment). A brand new .NET 4.7 class library created by VS 2017 contains the line <Import Project="$(FSharpTargetsPath)" />, which causes VS Code to fail loading the fsproj:

The value "" of the "Project" attribute in element is invalid. Parameter "path" cannot have zero length.

(I'd guess the missing element name <Project> is due to some bug in VS Code.)

This also leads to "namespace not found" errors.

Adding Condition="Exists('$(FSharpTargetsPath)')" to the <Project> element fixes the problem (and does not seem to break anything in VS 2017).

Using Ionide-fsharp 3.8.0 and VS Code 1.17.2.

cmeeren commented Oct 19, 2017

I'm experiencing a similar error as OP with successful workaround as in #132 (comment). A brand new .NET 4.7 class library created by VS 2017 contains the line <Import Project="$(FSharpTargetsPath)" />, which causes VS Code to fail loading the fsproj:

The value "" of the "Project" attribute in element is invalid. Parameter "path" cannot have zero length.

(I'd guess the missing element name <Project> is due to some bug in VS Code.)

This also leads to "namespace not found" errors.

Adding Condition="Exists('$(FSharpTargetsPath)')" to the <Project> element fixes the problem (and does not seem to break anything in VS 2017).

Using Ionide-fsharp 3.8.0 and VS Code 1.17.2.

@Firgeis

This comment has been minimized.

Show comment
Hide comment
@Firgeis

Firgeis Jan 16, 2018

Same problem as above when opening FSharp.Management, all projects fail to load

VS Code 1.19.2 Ionide 3.15.8

Firgeis commented Jan 16, 2018

Same problem as above when opening FSharp.Management, all projects fail to load

VS Code 1.19.2 Ionide 3.15.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment