MethodBoundaryAspect.Fody: Common Language Runtime detected an invalid program
Hi team, last week I have a bug on production site This is a case that caused bug (I call it as “FAKE” code - short code to reproduce):
[TimeTakenTrackLog]
public class Demo
{
public static async Task DoNothing()
{
}
public static async Task DemoBugAsync(int value)
{
if (value > 0)
{
await DoNothing();
}
}
}
// My page
[TimeTakenTrackLog] // applied on class
protected void Page_Load(object sender, EventArgs e)
{
Demo.DemoBugAsync(5).GetAwaiter().GetResult();
}
// My aspect attribute
public class TimeTakenTrackLogAttribute : OnMethodBoundaryAspect
{
public const string MessageQueueKey = "ImMethodTimeTakenMsgQueue";
public override void OnEntry(MethodExecutionArgs args)
{
}
public override void OnException(MethodExecutionArgs args)
{
}
public override void OnExit(MethodExecutionArgs args)
{
if (args.ReturnValue is Task t)
{
t.ContinueWith(task => {
BuildTimeTakenData(EventType.OnExitAsync, args);
EnqueueTrackMessage();
});
}
else
{
BuildTimeTakenData(EventType.OnExit, args);
EnqueueTrackMessage();
}
}
}
=> It’s just a piece of “real” code I applied to production last week (but it can cause error) => Fake code cause error on both DEBUG and RELEASE, local site & production site => “Real” code worked on Local (Debug mode)/TEST (Release mode) site BUT DID NOT work on Production site (RELEASE mode)
Here is a mini version of real code:
Caller:
WriteDbAccess.InitOrderRequestAndParseSubTrackData(new OrderRequestItem
{
OrderId = trackRequestData.OrderId,
SupplierId = supplierId,
OrderStatus = OrderStatus.New
}, NewPORequest, response).GetAwaiter().GetResult();
=> And here is method InitOrderRequestAndParseSubTrackData in class WriteDbAccess: I used Dapper btw
public static async Task InitOrderRequestAndParseSubTrackData(OrderRequestItem dto, NewPORequest xmlRequest, NewPOResponse xmlResponse)
{
using (var conn = new SqlConnection(Settings.ConnectionString))
{
conn.Open();
var poIdNumber = xmlRequest?.PurchaseOrder?.purchaseOrderId;
if (poIdNumber != null && poIdNumber > 0)
{
var exists = conn.ExecuteScalar<bool>("select top 1 1 from dbo.YOUR_TABLE where PurchaseOrderId = @poId", new { poId = poIdNumber.ToString() });
if (!exists)
{
var parms = new DynamicParameters();
parms.Add("@orderId", dto.OrderId);
parms.Add("@supplierId", dto.SupplierId);
parms.Add("@orderStatus", dto.OrderStatus);
await conn.ExecuteAsync("InsertOrderRequest", parms,
commandType: CommandType.StoredProcedure, commandTimeout: Settings.ConnectionTimeout);
await ParseOrderRequestSubTrackDataAsync(dto.OrderId, xmlRequest, xmlResponse);
}
}
}
}
Remember that Real code work on local and test site, but it did not work on Production site 😦
More images:


!!! FYI: My Aspect attribute work good, I have some web services and aspect worked for those services, only one of them did not work
This can be a bug of Fody , not MethodBoundaryAspect.Fody but I don’t know So anyone can explain why please
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 35
@alewmt It can be the most frustrating, I agree. I had one method where this issue appeared in “Release” configuration but not in “Debug” (I did try to repro in both configurations, btw). I don’t think this issue of the
br.saddress seeming to overflow is related to this defect though. This issue was being caused when fixing up theleaveinstructions.If you’re able to find code that can be used to repro the
br.saddress, create an issue, tag me and I’ll take a look at it if I get time.