Bug in Adapter code with AllowViewUpCasting???

Feb 29, 2008 at 5:40 AM
Hi all,

I add a new class in our common pipeline scenario like:
[PipelineHints.BaseClass(typeof(IDocContract))]
public interface IChildDocContract : IDocContract
{
...
}
and modify IDocContract like:
[PipelineHints.AllowViewUpCasting()]
public interface IDocContract : IContract
{
...
}
Here is our Adapter class:
internal static Samples.Common.IDoc ContractToViewAdapter(Samples.Common.Contracts.IDocContract contract)
{
System.AddIn.Contract.IContract subContract;
subContract = contract.QueryContract("Samples.Common.Contracts.IChildDocContract");
if ((subContract != null))
{
...
}
if (((System.Runtime.Remoting.RemotingServices.IsObjectOutOfAppDomain(contract) != true)
&& contract.GetType().Equals(typeof(IDocViewToContractAddInAdapter))))
{
...
}
else
{
...
}
}
internal static Samples.Common.Contracts.IDocContract ViewToContractAdapter(Samples.Common.IDoc view)
{
if (view.GetType().Equals(typeof(IDocContractToViewAddInAdapter)))
{
...
}
else
{
return new IDocViewToContractAddInAdapter(view);
}
}

I think the else branch in IDocContract ViewToContractAdapter(Samples.Common.IDoc view) should be:
else
{
if (view is IChildDoc)
return new IChildDocViewToContractAddInAdapter(view as IChildDoc);
return new IDocViewToContractAddInAdapter(view);
}

If Not, subContract = contract.QueryContract("Samples.Common.Contracts.IChildDocContract"); will always return null. :(
Mar 5, 2008 at 6:07 PM
Good catch, there is definitely a bug here. I went through this part of the code and found a few others as well. I'll include the fix for this in the next CTP (target for this is Friday).

Thanks,
Jesse