sebastienros / fluid

Fluid is an open-source .NET template engine based on the Liquid template language.
MIT License
1.44k stars 178 forks source link

MissingMethodException thrown after upgrading to 2.11.0 #683

Closed espenekvang closed 4 months ago

espenekvang commented 4 months ago

We upgraded from 2.10.0 to 2.11.0 but when trying to generate clients using CSharpClientGenerator and the method GenerateFile it now throws an exception:

_Unhandled exception. System.TypeInitializationException: The type initializer for 'LiquidTemplate' threw an exception.
 ---> System.MissingMethodException: Method not found: 'Parlot.Fluent.Parser`1<System.Collections.Generic.List`1<!!0>> Parlot.Fluent.Parsers.OneOrMany(Parlot.Fluent.Parser`1<!!0>)'.
   at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidParser..ctor()
   at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate..cctor()
   --- End of inner exception stack trace ---
   at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate..ctor(String language, String template, Func`3 templateContentLoader, Object model, String toolchainVersion, CodeGeneratorSettingsBase settings)
   at NJsonSchema.CodeGeneration.DefaultTemplateFactory.CreateTemplate(String language, String template, Object model)
   at NSwag.CodeGeneration.CSharp.CSharpClientGenerator.GenerateClientTypes(String controllerName, String controllerClassName, IEnumerable`1 operations)+MoveNext()
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateAllClientTypes()
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile(ClientGeneratorOutputType outputType)
   at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateFile()_

When downgrading to 2.10.0 of Fluid.Core the exception is no longer thrown.

sebastienros commented 4 months ago

It could mean that you have an old Parlot dll version sticking around. Or a direct reference to an old one. The current one to use is 1.0.0. Or the other way around actually, that there is something using the older version of Fluid which tries to use the old Parser<> ctor that appears in the log but doesn't exist anymore.

Since it's a generator, it's executed by the compiler or VS, so it is definitely possible that a restart/clean could fix it.

Can I try to repro it locally? I haven't used NSwag so I shouldn't hit this issue if that is the case, if you have a branch I can try.

espenekvang commented 4 months ago

Ok - thanks. I will try to look for an old dll first and let you know the result.

espenekvang commented 4 months ago

Closing this. The errors was caused by and implicit reference to Fluid.Core 2.9.0 from NSwag.CodeGeneration.CSharp. For us to upgrade to latest Fluid.Core we would need NSwag.CodeGeneration.CSharp to be upgraded first.

lahma commented 4 months ago

I've created a PR to update NJsonSchema's dependencies, including Fluid: https://github.com/RicoSuter/NJsonSchema/pull/1719

sebastienros commented 4 months ago

Thank you @lahma