C#表达式使用引用类型时Activity抛出异常 [英] Activity throws exception when C# expression uses reference types

查看:19
本文介绍了C#表达式使用引用类型时Activity抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原始的分配"活动.它从父序列的输入变量中获取值,并将它们放入父序列的输出变量中.如果我只是执行此复制操作,则一切正常并且工作流成功完成.如果我引入系统类型Random"或项目枚举ReportStatusType",工作流会抛出异常A System.NotSupportedException wasthrowed:"Expression Activity type ‘CSharpValue`1’需要编译才能运行."

I have a primitive "Assignment" activity. It takes values from an input variable for the parent sequence and puts them into an output variable for the parent sequence. If I simply perform this copy operation, everything works and the workflow completes successfully. If I introduce a system type "Random" or a project enum "ReportStatusType" the workflow throws an exception "A System.NotSupportedException was thrown: "Expression Activity type 'CSharpValue`1' requires compilation in order to run."

我根据 wf 4 的示例创建了此工作流程.我想我正在使用 wf 4.5.我在 VS2013 中工作并针对 .NET Framework 4.5.我使用了使用 IIS 平台的WCF 工作流服务应用程序"模板.我正在使用WCF 测试客户端"来调用服务并查看响应.

I created this workflow from an example for wf 4. I'm using wf 4.5, I think. I'm working in VS2013 and targeting .NET Framework 4.5. I used "WCF Workflow Service Application" template which uses an IIS platform. I'm using "WCF Test Client" to invoke the service and view the response.

这个价值表达有效:

new ExpenseReportConfirmation() {
       Amount = report.Amount,
       City = report.Amount,
       Client = report.Client,
       Employee = report.Employee,
       EndDate = report.EndDate,
       StartDate = report.StartDate,
       ReportID = 5
    };

此值表达式失败:

new ExpenseReportConfirmation() {
       Amount = report.Amount,
       City = report.Amount,
       Client = report.Client,
       Employee = report.Employee,
       EndDate = report.EndDate,
       StartDate = report.StartDate,
       ReportID = new Random().Next(0,5),
    };

我导入的命名空间如下所示:

My Imported Namespaces look like this:

如果我尝试在另一个分配活动中创建 ReportID,然后在上面显示的值表达式中引用它,这也会失败.它在 Random() 表达的任何地方都失败了.

This also fails if I try to create the ReportID in another assignment activity and then refer to it in the value expression shown above. It fails wherever Random() is expressed.

这可能是我的菜鸟错误,但我没有想法.其他人有吗?

This may be a rookie mistake on my part, but I'm out of ideas. Anyone else have any?

推荐答案

这个问题与编译 C# 表达式无关,因为我是在 IIS 下部署服务并处理编译.阅读 这篇 Visual Studio 反馈文章.我的作业活动值是这样写的,在包含Random()函数时总是抛出异常:

This issue had nothing to do with compiling the C# expressions since I was deploying the service under IIS and it handles the compilation. It was resolved after reading this Visual Studio Feedback article. My assignment activity value was written like this, and always threw an exception when the Random() function was included:

new ExpenseReportConfirmation() {
  Amount = report.Amount,
  City = report.City,
  Client = report.Client,
  Employee = report.Employee,
  EndDate = report.EndDate,
  StartDate = report.StartDate,
  ReportID = new Random().Next(0, 50)
};

我重新编写了这个表达式,一切正常:

I re-wrote the expression to this and everything works:

new ExpenseReportConfirmation() { Amount = report.Amount, City = report.City, Client = report.Client, Employee = report.Employee, EndDate = report.EndDate, StartDate = report.StartDate, ReportID = new Random().Next(0, 50) };

附注:我使用 WCF 测试客户端与我的工作流服务进行交互.当它捕获错误时,大量文本被转储给用户,包括服务响应的前 1024 个字节.我花了一段时间才学会深入挖掘所有这些并找到内部异常.以下是在文本转储底部附近查找内容的示例:

PS: I was using the WCF Test Client to interact with my workflow service. When it catches an error, a large amount of text is dumped to the user, including the first 1024 bytes of the service response. It took me a while to learn to dig down past all that and find the internal exception. Here is an example of what to look for near the bottom of the text dump:

[ConfigurationErrorsException: 扩展名 '.xalmx' 不是在 WCF/WF 处理程序中注册.

[ConfigurationErrorsException: The extension '.xalmx' is not registered with WCF/WF handler.

这篇关于C#表达式使用引用类型时Activity抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆