diff --git a/Svrnty.CQRS.Grpc/CqrsBuilderExtensions.cs b/Svrnty.CQRS.Grpc/CqrsBuilderExtensions.cs index d25fe68..e2228a5 100644 --- a/Svrnty.CQRS.Grpc/CqrsBuilderExtensions.cs +++ b/Svrnty.CQRS.Grpc/CqrsBuilderExtensions.cs @@ -33,6 +33,7 @@ public static class CqrsBuilderExtensions { Console.WriteLine("Warning: AddGrpcFromConfiguration not found. gRPC services were not registered."); Console.WriteLine("Make sure your project has source generators enabled and references Svrnty.CQRS.Grpc.Generators."); + DiagnoseGeneratedCode(); } // Register mapping callback for automatic endpoint mapping @@ -49,6 +50,59 @@ public static class CqrsBuilderExtensions return builder; } + private static void DiagnoseGeneratedCode() + { + var entryAsm = Assembly.GetEntryAssembly(); + if (entryAsm == null) + { + Console.WriteLine("Diagnostic: Entry assembly is null"); + return; + } + + Console.WriteLine($"Diagnostic: Entry assembly = {entryAsm.GetName().Name}"); + + try + { + var allTypes = entryAsm.GetTypes(); + Console.WriteLine($"Diagnostic: Total types in entry assembly = {allTypes.Length}"); + + var grpcTypes = allTypes + .Where(t => t.FullName?.Contains("Grpc") == true) + .ToList(); + + if (grpcTypes.Any()) + { + Console.WriteLine("Diagnostic: Found Grpc-related types:"); + foreach (var t in grpcTypes) + { + Console.WriteLine($" - {t.FullName} (IsClass={t.IsClass}, IsSealed={t.IsSealed}, IsPublic={t.IsPublic})"); + + // Check for our target method + var method = t.GetMethod("AddGrpcFromConfiguration", BindingFlags.Static | BindingFlags.Public); + if (method != null) + Console.WriteLine($" -> HAS AddGrpcFromConfiguration method!"); + } + } + else + { + Console.WriteLine("Diagnostic: No Grpc-related types found. Source generator did NOT run."); + } + } + catch (ReflectionTypeLoadException ex) + { + Console.WriteLine($"Diagnostic: ReflectionTypeLoadException - {ex.Message}"); + foreach (var le in ex.LoaderExceptions) + { + if (le != null) + Console.WriteLine($" LoaderException: {le.Message}"); + } + } + catch (Exception ex) + { + Console.WriteLine($"Diagnostic: Exception - {ex.GetType().Name}: {ex.Message}"); + } + } + private static MethodInfo? FindExtensionMethod(string methodName, Type parameterType) { // Search through all loaded assemblies for the extension method