-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
I'm getting "Common Language Runtime detected an invalid program" only on a service class in class library when I run my ASP.NET Core API in Docker on Linux, does not happen when ran with "F5" on Windows.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public class LoggingAspect : OnMethodBoundaryAspect
{
// NLog logger
//private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private static ILogger<LoggingAspect> _logger;
private static readonly AopLogOptions EnabledLogOptions;
static LoggingAspect()
{
EnabledLogOptions = LogOptionsHelper.GetEnabledLogOptions();
_logger = LoggerFactory.CreateLogger<LoggingAspect>(); // Ensure LoggerFactory is properly initialized
}
public override void OnEntry(MethodExecutionArgs args)
{
var declaringType = args.Method.DeclaringType;
if (declaringType != null && declaringType.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false))
{
return; // Skip logging for methods in compiler-generated classes
}
if (EnabledLogOptions.HasFlag(AopLogOptions.Entry))
{
_logger.LogInformation("Entering method {MethodName} with arguments: {Arguments}",
args.Method.Name,
args.Arguments);
}
}
public override void OnExit(MethodExecutionArgs args)
{
var declaringType = args.Method.DeclaringType;
if (declaringType != null && declaringType.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false))
{
return; // Skip logging for methods in compiler-generated classes
}
if (EnabledLogOptions.HasFlag(AopLogOptions.Exit))
{
_logger.LogInformation("Exiting method {MethodName} with return value: {ReturnValue}",
args.Method.Name,
args.ReturnValue);
}
base.OnExit(args);
}
public override void OnException(MethodExecutionArgs args)
{
// Log any exceptions that occur during execution
if (EnabledLogOptions.HasFlag(AopLogOptions.Exception))
{
_logger.LogError(args.Exception, "Exception in method {MethodName}", args.Method.Name);
}
}
}
[LoggingAspect]
//[TracingAspect]
public class PlacesAutocomplete : ServiceBase, IPlacesAutocomplete
{
public ILogger<PlacesAutocomplete> Logger { get; set; }
public IDal Dal { get; set; }
public PlacesAutocomplete(IDal dal, ILogger<PlacesAutocomplete> logger)
{
Logger = logger;
Dal = dal;
}
public async Task<PlaceDTO?> GetPlaceDetails(string googlePlaceId, string sessionId, string apiKey)
{
var place = await Dal.FindGooglePlace(googlePlaceId, false) ?? await Dal.FindGooglePlace(googlePlaceId, true);
var placeDto = new PlaceDTO();
if (place != null)
{
Logger.Log(LogLevel.Information, "Found a local database version of a place, sending response from database");
placeDto = TinyMapper.Map<PlaceDTO>(place);
return placeDto;
}
var fields = "address_component,adr_address,business_status,formatted_address,geometry,icon,name,photo,place_id,plus_code,type,url,vicinity,wheelchair_accessible_entrance";
var client = new RestClient("https://maps.googleapis.com/maps/api/");
var request = new RestRequest($"place/details/json?place_id={googlePlaceId}&fields={fields}&sessiontoken={sessionId}&key={apiKey}", Method.Get);
request.AddHeader("Accept", "application/json");
var googleResponse = await client.ExecuteAsync<GooglePlacesApiQueryResponse>(request);
if (googleResponse.Data != null)
{
var placeMongo = await Dal.SaveGooglePlace(googleResponse.Data.result, googlePlaceId);
placeDto = TinyMapper.Map<PlaceDTO>(placeMongo);
return placeDto;
}
placeDto = TinyMapper.Map<PlaceDTO?>(place);
return placeDto;
}
// [END PlacesAutocomplete]
Metadata
Metadata
Assignees
Labels
No labels