Add diagnostic logging when gRPC generated code not found
All checks were successful
Publish NuGets / build (release) Successful in 37s
All checks were successful
Publish NuGets / build (release) Successful in 37s
When AddGrpcFromConfiguration method is not found via reflection, logs detailed diagnostics to help identify the root cause: - Entry assembly name and total type count - All Grpc-related types with their IsClass/IsSealed/IsPublic flags - Whether the target method exists on each type - ReflectionTypeLoadException details if type loading fails Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
18f81a28e8
commit
20147bfec7
@ -33,6 +33,7 @@ public static class CqrsBuilderExtensions
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Warning: AddGrpcFromConfiguration not found. gRPC services were not registered.");
|
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.");
|
Console.WriteLine("Make sure your project has source generators enabled and references Svrnty.CQRS.Grpc.Generators.");
|
||||||
|
DiagnoseGeneratedCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register mapping callback for automatic endpoint mapping
|
// Register mapping callback for automatic endpoint mapping
|
||||||
@ -49,6 +50,59 @@ public static class CqrsBuilderExtensions
|
|||||||
return builder;
|
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)
|
private static MethodInfo? FindExtensionMethod(string methodName, Type parameterType)
|
||||||
{
|
{
|
||||||
// Search through all loaded assemblies for the extension method
|
// Search through all loaded assemblies for the extension method
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user