[英]Is this type assignment error a bug in WCF or Windows Workflow Foundation 4.5?
I have a Windows Workflow Foundation 4.5 WCF Workflow Service Application. 我有一个Windows Workflow Foundation 4.5 WCF工作流服务应用程序。 I am attempting to return a
Dictionary<IEdmEntityType, DataTable>
from my CodeActivity<Dictionary<IEdmEntityType, DataTable>>
. 我试图从我的
CodeActivity<Dictionary<IEdmEntityType, DataTable>>
返回Dictionary<IEdmEntityType, DataTable>
。 The code does not encounter a compile time error, but the XAML fails to compile. 代码不会遇到编译时错误,但XAML无法编译。
The relevant parts of my XAML are like so: 我的XAML的相关部分是这样的:
We have the variable declarations for the sequence, where I am trying to dump my return value. 我们有序列的变量声明,我试图转储我的返回值。 The variable we're trying to assign to is called
EntityTableRelationships
. 我们尝试分配的变量称为
EntityTableRelationships
。
<p1:Sequence.Variables>
<p1:Variable x:TypeArguments="x:String" Name="MetadataContent" />
<p1:Variable x:TypeArguments="scg:Dictionary(mde:IEdmEntityType, sd:DataTable)" Name="EntityTableRelationships" />
</p1:Sequence.Variables>
There is also the OutArgument
, the return value from Execute
, from our CodeActivity<..>
being assigned to EntityTableRelationships
. 还有
OutArgument
,来自Execute
的返回值,来自我们的CodeActivity<..>
被分配给EntityTableRelationships
。
<o:TransformMetadataToTables.Result>
<p1:OutArgument x:TypeArguments="scg:Dictionary(mde:IEdmEntityType, sd:DataTable)">
<mca:CSharpReference x:TypeArguments="scg:Dictionary(mde:IEdmEntityType, sd:DataTable)">EntityTableRelationships</mca:CSharpReference>
</p1:OutArgument>
</o:TransformMetadataToTables.Result>
The XAML validation error being produced is: 产生的XAML验证错误是:
Type 'http://schemas.microsoft.com/netfx/2009/xaml/activities:OutArgument(Dictionary)' is not assignable to type 'http://schemas.microsoft.com/netfx/2009/xaml/activities:OutArgument(Dictionary)' of member 'EntityTableRelationships'.
Initially I had thought that I typed my return value incorrectly or maybe I was referencing an interface with the same name but in a different namespace. 最初我以为我错误地键入了我的返回值,或者我可能引用了一个名称相同但位于不同名称空间的接口。 This is not the case.
不是这种情况。
Another thought I had was that maybe the workflows do not play nice with any Dictionary<TKey, TValue>
declaring TKey
as any interface. 我的另一个想法是,可能工作流程不能很好地与任何
Dictionary<TKey, TValue>
声明TKey
作为任何接口。 I made a test case that does this and it worked fine. 我做了一个测试案例,它做到了这一点并且运行良好。 I also added that step into the designer and in a sequence, just as is done here.
我还将这一步添加到设计器中并按顺序添加,就像在此处所做的那样。 I did not try it with
IEdmEntityType
as the TKey
, but there is no reason, that I can see, as to why it should be any different. 我没有尝试使用
IEdmEntityType
作为TKey
,但没有理由,我可以看到,为什么它应该是任何不同的。
What could be the cause of this and how can I fix it? 可能是什么原因以及如何解决?
EDIT #1 编辑#1
Further research has indicated that the DataTable
is the culprit. 进一步的研究表明,
DataTable
是罪魁祸首。 DataSet
also has the problem. DataSet
也有问题。 The only thing I can see that is unique about these types is that they inherit from MarshalByValueComponent
which has a TypeConverterAttribute
on it. 我唯一可以看到的是这些类型的独特之处在于它们继承自
MarshalByValueComponent
,它上面有一个TypeConverterAttribute
。 That TypeConverter
could be influencing the XAML serialization binder and causing issues, thus indicating a bug in WF 4.5. TypeConverter
可能会影响XAML序列化绑定器并导致问题,从而表明WF 4.5中存在错误。 But, I am hesitant to say this is a bug. 但是,我犹豫是否说这是一个错误。
No Dictionary<TKey, DataTable>
can be passed around in WF 4.5 via the designer, it seems. 似乎没有
Dictionary<TKey, DataTable>
可以通过设计师在WF 4.5中传递。
EDIT #2 编辑#2
It seems it may or may not have anything to do with the DataTable
. 它似乎可能与
DataTable
,也可能没有。 You also cannot pass around Dictionary<IEdmEntityType, object>
. 你也无法传递
Dictionary<IEdmEntityType, object>
。
To try and reproduce the issue with classes outside of System.Data
and other than System.Object
, I made a new workflow project. 为了尝试使用
System.Data
以外的类而不是System.Object
重现该问题,我创建了一个新的工作流项目。
I created my own interface, classes, and structs to see if there was anything that would trigger it to break again. 我创建了自己的接口,类和结构,以查看是否有任何东西会触发它再次中断。
Instead of using IEdmEntityType
, I made IMyInterface
which is just defined as: 而不是使用
IEdmEntityType
,我做了IMyInterface
这是刚刚定义为:
public interface IMyInterface
{
int Id
{
get;
}
}
The MyStruct
struct worked fine. MyStruct
结构很好。 This is the definition: 这是定义:
public struct MyStruct
{
public int A;
public int B;
}
The MyClass
class worked fine. MyClass
类运行良好。 This is the definition: 这是定义:
public class MyClass
{
public int A;
public int B;
}
MyClassComplex
with automatic properties and a reference to an object
also worked. 具有自动属性和
object
引用的MyClassComplex
也起作用。
public class MyClassComplex
{
public int A
{
get;
private set;
}
public int B
{
get;
private set;
}
public object C
{
get;
private set;
}
}
I also thought originally that it might have something to do with the common attributes between DataTable
and DataSet
, so I added them to MyClassComplex
, but it still worked fine. 我最初也认为它可能与
DataTable
和DataSet
之间的公共属性有关,所以我将它们添加到MyClassComplex
,但它仍然工作正常。
Additionally, I had MyClassComplex
inherit from MarshalByValueComponent
, and there was no odd interaction, no errors once again. 另外,我让
MyClassComplex
继承了MarshalByValueComponent
,没有奇怪的交互,再也没有错误。
I took this same project and simply set my variable as a Dictionary<IMyInterface, DataTable>
and altered the CodeActivity<IMyInterface, MyClassComplex>
to CodeActivity<IMyInterface, DataTable>
, and it gave the same error as in my original non-test project. 我接受了同样的项目并简单地将我的变量设置为
Dictionary<IMyInterface, DataTable>
并将CodeActivity<IMyInterface, MyClassComplex>
更改为CodeActivity<IMyInterface, MyClassComplex>
CodeActivity<IMyInterface, DataTable>
,并且它给出了与我原来的非测试项目相同的错误。
EDIT #3 编辑#3
Since I have tested this and reproduced the issue in separate projects and on a colleague's machine and no documentation supports why this should not work, I have filed a bug report on MS Connect 由于我已经在单独的项目和同事的机器上对此进行了测试并重现了该问题,并且没有文档支持为什么这不起作用,我已经提交了有关MS Connect的错误报告
Apparently Windows Workflow Foundation includes a specific version of Microsoft.Data.OData
and adding the ODataLib NuGet package to the project conflicts with that. 显然,Windows Workflow Foundation包含特定版本的
Microsoft.Data.OData
并且将ODataLib NuGet包添加到项目与之冲突。 I searched around for where the reference is included originally and it turns out it is silently added during code generation as part of the workflow designer's code generation process. 我搜索了最初包含引用的位置,事实证明它是在代码生成期间默默添加的,作为工作流设计器代码生成过程的一部分。
At no point was there any error on the client side that indicated some assembly version conflict. 在客户端没有任何错误表明某些程序集版本冲突。 As far as I know, there's no way to get around this.
据我所知,没有办法解决这个问题。 Microsoft has closed the ticket as "by design".
微软已经将该机票关闭为“按设计”。
Just for simplify the case, it also happens if you try to assign double value/variable to a double variable. 只是为了简化案例,如果您尝试将double value / variable赋值给double变量,也会发生这种情况。 It was working before 4.5 but now it does not.
它在4.5之前工作但现在却没有。
Non touched Wf definitions just stop working upgrading the framework. 未触及的Wf定义只是停止升级框架。
We have solved it manually modifying .xaml from x:Object to x:Double in both Target and Origin variables from the Assign activity. 我们已经解决了手动修改.xaml从x:Object到x:来自Assign活动的Target和Origin变量的两倍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.