Meziantou.Framework
Meziantou.Framework copied to clipboard
The type or namespace name 'StronglyTypedIdAttribute' could not be found
I created a Username struct like this in an ASP.NET Core 6 application:
[StronglyTypedId(idType: typeof(string),
generateSystemTextJsonConverter: true,
generateNewtonsoftJsonConverter: true,
generateSystemComponentModelTypeConverter: true,
generateMongoDBBsonSerialization: true,
addCodeGeneratedAttribute: true
)]
public partial struct Username { }
When compiling, I get this error:
Types.cs(31, 2): [CS0246] The type or namespace name 'StronglyTypedIdAttribute' could not be found (are you missing a using directive or an assembly reference?)
I tried adding a using statement like this:
using Meziantou.Framework.StronglyTypedId;
However, this results in
Cannot resolve symbol 'Meziantou'`
Using directive is not required by the code and can be safely removed
My package reference looks like this:
<PackageReference Include="Meziantou.Framework.StronglyTypedId" Version="1.0.22">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
What am I doing wrong here?
Can you share repro steps? Does the following work on your machine?
-
dotnet new web -
dotnet add package Meziantou.Framework.StronglyTypedId -
Add a new file with the content
[StronglyTypedId(typeof(int))] public partial struct ProjectId { } -
dotnet build
Also, which version of the compiler do you use? https://www.meziantou.net/getting-roslyn-csharp-compiler-and-language-versions.htm
Can you share repro steps? Does the following work on your machine? dotnet new web dotnet add package Meziantou.Framework.StronglyTypedId Add a new file with the content [StronglyTypedId(typeof(int))] public partial struct ProjectId { } dotnet build
The repro fails with the same error.
Also, which version of the compiler do you use? https://www.meziantou.net/getting-roslyn-csharp-compiler-and-language-versions.htm
ProjectId.cs(3, 8): [CS8304] Compiler version: '4.0.1-1.22181.2 (487283bc)'. Language version: 10.0.
I'm using Xubuntu 22.04 with the new dotnet 6 packages provided by Canonical.
The CI run on Windows and Ubuntu 22.04, so it should work. And I build multiple projects on Linux using this package. What I can see is that the compiler is not up-to-date (but I think it should work). You can try to download the latest sdk (linux binaries x64) https://dotnet.microsoft.com/en-us/download/dotnet/6.0 and try with the dotnet from the zip file.
If it doesn't work, can you build using dotnet build /bl to generate a binary log file (msbuild.binlog). This log file contains all your environment variables, so be sure to build the project in a context that is not problematic. You can upload the file here.