Refit: Build fails when project name includes spaces

Created on 28 Mar 2019  路  4Comments  路  Source: reactiveui/refit

Refit creates RefitStubs.g.cs in PROJECT_NAME.RefitInternalGenerated namespace, so when project name contains characters which are not allowed to use in namespaces build fails.

1>obj\Debug\netcoreapp2.2\RefitStubs.g.cs(13,26,13,48): error CS0116: A namespace cannot directly contain members such as fields or methods
1>obj\Debug\netcoreapp2.2\RefitStubs.g.cs(13,22,13,25): error CS1514: { expected
1>obj\Debug\netcoreapp2.2\RefitStubs.g.cs(13,25,13,26): error CS1022: Type or namespace definition, or end-of-file expected
1>obj\Debug\netcoreapp2.2\RefitStubs.g.cs(14,1,14,2): error CS1022: Type or namespace definition, or end-of-file expected
1>Done building project "Playground App.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

C# language specification says that namespace name is an identifier, so all rules which are applicable to identifiers are also applicable to namespaces (namespace can't start from digit, etc.).

Project name rules are not to strict. My VS says that all valid NTFS directory names are allowed to use as project name.

So there are some limitations for project/solution names, it can't:

  • contain any of the following characters / ? : & \ * " < > | # %
  • contain Unicode control characters
  • contain invalid surrogate characters
  • be system reserved names, including CON, AUX, PRN, COM1 or LPT2
  • be . or ..
bug

All 4 comments

Refit uses the $(RootNamespace) property (or $(RefitInternalNamespace) property if set in the project file) to add to the namespace of the PreserveAttribute.

I tested with a blank new .NET Standard class library and a .NET Core Console App, with spaces in the project names; and it doesn't give me any problems.

Could you provide a small sample that reproduces this?

Sure. Note that is not set manually is csproj.
When you create a blank project with spaces in name, VS will add sanitized namespace to <RootNamespace>, but when you rename existing project no additional info will be added to csproj.

@hankovich Thanks for the repro. I will look into it.

Closing due to age. Please try Refit v6 and reopen if still an issue.

Was this page helpful?
0 / 5 - 0 ratings