C
C#•3w ago
Okno

Compilation issue with source generator

Hello there, I am building a mapper source generator to learn Csharp. I am now testing it in a real project. Unfortunately using it as a dependency seems to trigger the following compilation error:
/usr/local/share/dotnet/sdk/8.0.402/Roslyn/Microsoft.CSharp.Core.targets(85,5): error MSB6006: "csc.dll" exited with code 1. [/Users/pauldelafosse/Code/di-business-meta-app/di-business-file-import/BusinessFileImport.Infrastructure.Persistence/BusinessFileImport.Infrastructure.Persistence.csproj]
/usr/local/share/dotnet/sdk/8.0.402/Roslyn/Microsoft.CSharp.Core.targets(85,5): error MSB6006: "csc.dll" exited with code 1. [/Users/pauldelafosse/Code/di-business-meta-app/di-business-file-import/BusinessFileImport.Infrastructure.Persistence/BusinessFileImport.Infrastructure.Persistence.csproj]
I have looked up this error code but I am really unsure what could be done to diagnose this. For reference the source generator repo is here: https://github.com/oknozor/CartographeAutomatique/tree/main Any advice on how to troubleshot this would be appreciated.
GitHub
GitHub - oknozor/CartographeAutomatique: For now just a C# learning...
For now just a C# learning project. Contribute to oknozor/CartographeAutomatique development by creating an account on GitHub.
18 Replies
ero
ero•3w ago
Write a proper unit test instead of "testing it in another project".
Okno
OknoOP•3w ago
Well I think if you had taken time to open the link you would have seen the "proper unit tests"
Sehra
Sehra•3w ago
gave it a try and samples compile and tests pass (beside the Debugger.Launch spam). guessing there is a MapTo/MapFrom in your code that trigger some bug not covered by the unit tests
Okno
OknoOP•3w ago
Maybe unrelated but rider seem unable to resolve namespace correctly in the generated code
No description
canton7
canton7•3w ago
Can you make that screenshot bigger so that it doesn't clip the right-hand side (or just post text)?
Okno
OknoOP•3w ago
otherwise, copy and pasting the generated code in the project as non generated code compiles
// <auto-generated/>
namespace Agicap.DataIntegration.BusinessFileImport.Infrastructure.Persistence.CustomerFile;

public static partial class CustomerFileEntityMappingExtensions
{
public static Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.CustomerFile.CustomerFileSnapshot MapToCustomerFileSnapshot(this Agicap.DataIntegration.BusinessFileImport.Infrastructure.Persistence.CustomerFile.CustomerFileEntity source) =>
new(Id: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.CustomerFile.CustomerFileId(source.Id),AssociatedMatrixId: source.MatrixId.MapToMatrixId(),SynchronizationId: CustomerFileEntity.MapSynchronizationId(source.SynchronizationId),FileMatrixFileId: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.FileMatrixFileId(source.FileMatrixFileId),FileName: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.File.FileName(source.FileName),ReadUrl: source.ReadUrl,ContentType: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.File.ContentType(source.ContentType),SynchronizationStatus: (Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.SynchronizationStatus)Enum.Parse(typeof(Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.SynchronizationStatus), source.SynchronizationStatus),UploadState: (Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.UploadState)Enum.Parse(typeof(Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.UploadState), source.UploadState),CreatedAtUtc: source.CreatedAtUtc,UpdatedAtUtc: source.UpdatedAtUtc);
}
// <auto-generated/>
namespace Agicap.DataIntegration.BusinessFileImport.Infrastructure.Persistence.CustomerFile;

public static partial class CustomerFileEntityMappingExtensions
{
public static Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.CustomerFile.CustomerFileSnapshot MapToCustomerFileSnapshot(this Agicap.DataIntegration.BusinessFileImport.Infrastructure.Persistence.CustomerFile.CustomerFileEntity source) =>
new(Id: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.CustomerFile.CustomerFileId(source.Id),AssociatedMatrixId: source.MatrixId.MapToMatrixId(),SynchronizationId: CustomerFileEntity.MapSynchronizationId(source.SynchronizationId),FileMatrixFileId: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.FileMatrixFileId(source.FileMatrixFileId),FileName: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.File.FileName(source.FileName),ReadUrl: source.ReadUrl,ContentType: new Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.File.ContentType(source.ContentType),SynchronizationStatus: (Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.SynchronizationStatus)Enum.Parse(typeof(Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.SynchronizationStatus), source.SynchronizationStatus),UploadState: (Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.UploadState)Enum.Parse(typeof(Agicap.DataIntegration.BusinessFileImport.Domain.FileImportConnections.UploadState), source.UploadState),CreatedAtUtc: source.CreatedAtUtc,UpdatedAtUtc: source.UpdatedAtUtc);
}
sorry about the ident, this is generated source
Sehra
Sehra•3w ago
you can shorten the enum handling a bit to $"Enum.Parse<{target.FullyQualifiedName()}>({sourceIdentifier})"
Okno
OknoOP•3w ago
sure but I am not sure that will solve my issue 😦
Sehra
Sehra•3w ago
most likely not, but will make the generated code prettier but you have a test case in BusinessFileImport.Infrastructure.Persistence that you can try to run using the testing code and see what it complains about
Okno
OknoOP•3w ago
that's the whole point, compilation fail and I get the following error
11>Microsoft.CSharp.Core.targets(85,5): Error MSB6006 : "csc.dll" exited with code 1.
11>Microsoft.CSharp.Core.targets(85,5): Error MSB6006 : "csc.dll" exited with code 1.
` I don't have any other relevant logs. I will try to make a smaller reproducer in a dedicated project
Sehra
Sehra•3w ago
try with dotnet build /bl and look in the binary logs, maybe the error output is supressed by msbuild can view logs with https://msbuildlog.com/
Okno
OknoOP•3w ago
Not sure where to look, but it does not seem I have additional error here.
No description
Sehra
Sehra•3w ago
didn't seem to provide more detail. could try running the full command manually and see if csc just crashes or output anything else
Okno
OknoOP•3w ago
Ok I have finally managed to make it compile, I. missed an error in the generated source (calling an undeclared method). However any error in the generated source, would still generate this csc.dll error code and silence the compiler errors. This would be really frustrating for end users. I am a bit puzzled because those compiler errors are correctly emitted in my test project. Also I was relying on those to guide the user to write correct mappings attributes, instead of doing a lot of code analysis to produce the correct compiler diagnostics. the bug seems to be somehow related to https://github.com/dotnet/roslyn/issues/24736 But this is supposed to be closed.
333fred
333fred•3w ago
So I'm not able to reproduce that failure method. I cloned your repo and checked out 4a3caf1, and then modified your generator to introduce errors And I see plenty of errors in the console when I run dotnet build I will say your generator needs some work. Do not store symbols in your generator models; please give $ig a read
MODiX
MODiX•3w ago
If you want to make an incremental source generator, please make sure to read through both the design document and the cookbook before starting.
Okno
OknoOP•3w ago
guess what, I did
canton7
canton7•3w ago
You did give the design doc a read? Then great, you'll know that you can't store symbols in your generator models, and you'll know why 🙂

Did you find this page helpful?