C
C#2y ago
Binto86

Could not load file or assembly 'System.Collections.Imutable' when using source generators

I am trying source generators, and now i am getting warning
Generator failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
Generator failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
i am pretty sure that this error has something to do with context.AdditionalFiles as it didn't occur when i didn't use them, this is my code:
public void Execute(GeneratorExecutionContext context)
{
var mainMethod = context.Compilation.GetEntryPoint(context.CancellationToken);
for (int i = 0; i < context.AdditionalFiles.Length; i++)
{
var file = context.AdditionalFiles[i];
if (file.Path.EndsWith(".py"))
{
var ClassName = Path.GetFileNameWithoutExtension(file.Path);
string source = $@"
// <auto-generated/>
{PythonGenerator.GenerateClass(file.Path, mainMethod.ContainingNamespace.Name)}
";


// Add the source code to the compilation
context.AddSource($"{ClassName}.g.cs", source);
}
}
}
public void Execute(GeneratorExecutionContext context)
{
var mainMethod = context.Compilation.GetEntryPoint(context.CancellationToken);
for (int i = 0; i < context.AdditionalFiles.Length; i++)
{
var file = context.AdditionalFiles[i];
if (file.Path.EndsWith(".py"))
{
var ClassName = Path.GetFileNameWithoutExtension(file.Path);
string source = $@"
// <auto-generated/>
{PythonGenerator.GenerateClass(file.Path, mainMethod.ContainingNamespace.Name)}
";


// Add the source code to the compilation
context.AddSource($"{ClassName}.g.cs", source);
}
}
}
3 Replies
333fred
333fred2y ago
Remember, #roslyn is a thing I suspect you have mismatched dependency versions between the version of VS you're using and the version of roslyn you're using
Binto86
Binto862y ago
ok... and what can i do about it?
333fred
333fred2y ago
Line them up You need to use the appropriate version of roslyn for the version of VS you want to run on
Want results from more Discord servers?
Add your server
More Posts
Generating random numbers (int32) [Answered]As you may know ``Guid.NewGuid()`` returns a 128bit random "number" which is very unlikely to get duVisual Studio doesn't work as expected with source generators [Answered]I wanted to give source generators a try, i followed Microsoft tutorial and everything worked as expBlazor WASM Hosted uses wrong basepath on page reloadHello! I have a web app that mostly works as it should, except on a Page Refresh or direct accessingCalling a static abstract method without a generic type [Answered]If I have this code with a static abstract member `Bar` in the interface `IFoo`, is there *any way* WinUI3 app doesn't run outside of Visual StudioI just tried to share a tool I made in WinUI3 with .NET6. That shouldn't be a problem with the publiLearning Agile and Scrum on my own, looking for advice, resources, insightsI haven't had the chance to work both in groups of developers nor in groups of developers working unProper C multicatch syntaxI saw in Java that you can do multicatch blocks (see image) I also looked it up on stackoverflow: Change output directory of nuget packageUsually, nuget package assemblies and dependencies are copied to OutDir during build, e.g. `bin\DebuCan someone help me? I got this errorHi, so i have table `Laporan_Penilaian` form another `database`. When i tried to run my project i goHow to use custom DateTimeConverter for selected endpoints?I have the following converter which is responsible for reading and returning dates in UTC format: `