Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatical API: Could not load file or assembly 'Namotion.Reflection #188

Open
jonashw opened this issue Jan 23, 2024 · 1 comment
Open

Comments

@jonashw
Copy link

jonashw commented Jan 23, 2024

First of all, what an exciting library! I'm eager to apply it to my project.

I've been unable to overcome the following exception with a bare-minimum usage of the programmatical API and .NET 7.

Could not load file or assembly 'Namotion.Reflection, Version=2.1.1.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102'. The system cannot find the file specified.
at TypeGen.Core.Extensions.TypeExtensions.IsNullable(MemberInfo memberInfo)
at TypeGen.Core.Generator.Services.TypeService.GetTypeUnions(MemberInfo memberInfo)
at TypeGen.Core.Generator.Generator.GetInterfacePropertyText(Type type, MemberInfo memberInfo)
at TypeGen.Core.Generator.Generator.<>c__DisplayClass51_0.b__0(String current, MemberInfo memberInfo)
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func)
at TypeGen.Core.Generator.Generator.GetInterfacePropertiesText(Type type)
at TypeGen.Core.Generator.Generator.GenerateInterface(Type type, ExportTsInterfaceAttribute interfaceAttribute)
at TypeGen.Core.Generator.Generator.GenerateType(Type type)
at TypeGen.Core.Generator.Generator.<>c__DisplayClass33_0.b__0()
at TypeGen.Core.Generator.Generator.ExecuteWithTypeContextLogging(Action action)
at TypeGen.Core.Generator.Generator.GenerateMarkedType(Type type)
at TypeGen.Core.Generator.Generator.Generate(IEnumerable`1 generationSpecs)
at TypeScriptGeneratorSample.Program.Main(String[] args) in C:\Users\jonashw\GitRepos\TypeScriptGeneratorSample\Program.cs:line 12

tgconfig.json:

{
  "outputPath": "generated",
  "generationSpecs": [ "SampleGenerationSpec" ]
}

C# source:

using TypeGen.Core.Generator;
using TypeGen.Core.SpecGeneration;

namespace TypeScriptGeneratorSample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            var gen = new Generator();
            gen.Generate(new[] { new SampleGenerationSpec() });
        }
    }

    public class SampleGenerationSpec : GenerationSpec
    {
        public override void OnBeforeGeneration(OnBeforeGenerationArgs args)
        {
            AddInterface(typeof(SampleRecord));
        }
    }

    public record SampleRecord(int Id, string Name, DateTime Created, bool Active);
}

Curiously, I've been able to make SampleGenerationSpec work via dotnet-typegen generate without an issue.

generated/sample-record.ts:

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export interface SampleRecord {
    id: number;
    name: string;
    created: Date;
    active: boolean;
}

Am I doing something wrong or have I discovered a bug?

@millokeller
Copy link

I'm encountering the same issue with .NET 6.0 and TypeGen 5.0.1. The only solution I've found is to manually add a package reference to Namotion.Reflection:
<PackageReference Include="Namotion.Reflection" Version="2.1.1" />

Would it be possible to include Namotion.Reflection as a dependency in the TypeGen NuGet package to streamline the setup process and prevent this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants