带有 IObservable 的 MethodCallExpression 向 System.CoreEx 抛出访问被拒绝异常

发布于 2024-09-26 04:57:21 字数 875 浏览 2 评论 0原文

我有一个 MethodCallExpression 对象,我尝试使用 Reactive Extensions 框架从该对象返回一个 IObservable 实例。

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   Func<Thing> method = expression.Compile()
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   IObservable<Thing> observable = observable();
   return observable;
}

问题是,当执行此命令时,我在 observable() 上收到以下运行时异常:

无法加载文件或程序集“System.CoreEx,Version=1.0.2617.104,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。访问被拒绝。

如果我在没有反应性框架的情况下运行该方法,一切都很好。

 Thing item = method();

有什么想法造成这种情况吗?所有程序集引用均已添加。

编辑 我应该补充一点,所讨论的表达式包含一个在使用 Moq 创建的模拟对象上执行的方法。

I have a MethodCallExpression object from which I'm trying to return a IObservable<Thing> instance using the Reactive Extensions framework.

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   Func<Thing> method = expression.Compile()
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   IObservable<Thing> observable = observable();
   return observable;
}

The issue is that when this executes I get the following runtime exception on observable():

Could not load file or assembly 'System.CoreEx, Version=1.0.2617.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied.

If I run the method without the Reactive framework everything is fine.

 Thing item = method();

Any ideas what's causing this? All assembly references are added.

Edit I should add that the expression in question contains a method which executes on a Mocked object created using Moq.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2024-10-03 04:57:22

是否为当前用户安装了反应式框架?您对此文件有读取/可执行权限吗?

Is reactive framework installed for the current user? do you have read/executable access to this file?

你列表最软的妹 2024-10-03 04:57:22

好吧,我设法让它工作,尽管我从未真正了解访问被拒绝问题的根源。可能是重启后解决了这个问题。在剥离我的代码并重建它之后,我开始遇到不同的错误:

The object must be a runtime Reflection object

然后我将代码更改为在应用 Rx 之前将方法调用包装到 Action 中,并且这有效:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> = () => method();
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   return observable();
}

据记录我能够进一步减少这种情况:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> action = () => method();
   return Observable.Start(action);
}

Well I managed to get it working, although I never really got to the bottom of the Access Denied issue. It may have been a reboot that resolved it. After stripping my code right back and rebuilding it I starting getting a different error:

The object must be a runtime Reflection object

I then changed the code to wrap to method invoke into an Action before applying Rx, and this worked:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> = () => method();
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   return observable();
}

For the record I was able to reduce this further:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> action = () => method();
   return Observable.Start(action);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文