You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a problem with the Unity.Interception extension (using Unity v4.0.1 and Unity.Interception v4.0.1) and VirtualMethodInterception.
Since the issue is a bit difficult to explain, I attached a console application that reproduces the issue. Basically, I have some "domain objects" that look something like this:
public interface IDataImportJob
{
void Run();
}
public abstract class DataImportBase : IDataImportJob
{
public virtual void Run()
{
OnRun();
}
protected abstract bool OnRun();
}
public interface IProductPartAndOptionMasterDataImport : IDataImportJob
{
}
public class ProductPartAndOptionMasterDataImport : DataImportBase, IProductPartAndOptionMasterDataImport
{
private readonly IOtherObject _otherObject;
public ProductPartAndOptionMasterDataImport(IOtherObject otherObject)
{
_otherObject = otherObject;
}
protected override bool OnRun()
{
var productsOk = RunProductPartAndOptionImport();
return productsOk;
}
protected virtual bool RunProductPartAndOptionImport()
{
int partsProcessed = 42;
ImportProductPartFromProduct(ref partsProcessed);
return true;
}
[TracingCallHandler(true, true, true)]
// if you remove the "partsProcessed" parameter here, the issue does not occur.
protected virtual void ImportProductPartFromProduct(ref int partsProcessed)
{
int someParameter = 0;
_otherObject.SomeMethod(ref someParameter);
}
}
public interface IOtherObject
{
void SomeMethod(ref int someArgument);
}
public class OtherObject : IOtherObject
{
public virtual void SomeMethod(ref int someArgument)
{
throw new Exception("Something bad happened.");
}
}
The TracingCallHandler is a CallHandler that can log and swallow exceptions.
Now, when I run the console application, the "Something bad happened" exception is logged as expected, but then I get a second exception
(System.ArgumentOutOfRangeException) that crashes the application.
I guess the problem is that somewhere in the dynamically generated code (DynamicModule.ns.Wrapped_ ...) a ParameterCollection is
created with an empty arguments array. Then, the indexer of that ParameterCollection is used with an index of 0, which will eventually result in that System.ArgumentOutOfRangeException.
If you remove the partsProcessed parameter from the ImportProductPartFromProduct method, the issue does not occur.
The text was updated successfully, but these errors were encountered:
@kostemar Wrote:
I ran into a problem with the Unity.Interception extension (using Unity v4.0.1 and Unity.Interception v4.0.1) and VirtualMethodInterception.
Since the issue is a bit difficult to explain, I attached a console application that reproduces the issue. Basically, I have some "domain objects" that look something like this:
The TracingCallHandler is a CallHandler that can log and swallow exceptions.
Now, when I run the console application, the "Something bad happened" exception is logged as expected, but then I get a second exception
(System.ArgumentOutOfRangeException) that crashes the application.
I guess the problem is that somewhere in the dynamically generated code (DynamicModule.ns.Wrapped_ ...) a ParameterCollection is
created with an empty arguments array. Then, the indexer of that ParameterCollection is used with an index of 0, which will eventually result in that System.ArgumentOutOfRangeException.
If you remove the partsProcessed parameter from the ImportProductPartFromProduct method, the issue does not occur.
The text was updated successfully, but these errors were encountered: