HyperDescriptor在内置.NET 4时是否工作? [英] Does HyperDescriptor work when built in .NET 4?

查看:163
本文介绍了HyperDescriptor在内置.NET 4时是否工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个.NET 4项目,并且可以从动态属性访问中获益,这些访问是 HyperDescriptor 提供,但它内置于.NET 4中似乎不能正常工作。我从CodeProject下载源代码,将解决方案的项目转换为VS2010,并将目标框架更新为4.0。当它构建并且示例正确执行时,这些时间表明HyperDescriptor的动态属性访问是获取/设置对象值的可能方式。

I'm working on a .NET 4 project, and would be able to benefit from the dynamic property access that HyperDescriptor provides, but it doesn't seem to be working properly when built in .NET 4. I downloaded the source from CodeProject, converted the solution an projects to VS2010, and updated the target framework to 4.0. While it builds, and the sample executes correctly, the timings show that dynamic property access with HyperDescriptor is the slowest possible way of getting/setting object values.

只有当您使用.NET 4从源代码构建HyperDescriptor时,才会出现此问题。如果从.NET 4项目中添加了使用.NET 2构建的HyperDescriptor的引用,则可以正常工作。现在这是一个可以接受的解决方案,但使用.NET 4构建会有一些潜在的优势吗?任何人想要在HyperDescriptor上进行破解,看看为什么使用.NET 4构建这么慢?

This problem is only when you build HyperDescriptor from source with .NET 4. If from your .NET 4 project, you add a reference to HyperDescriptor built with .NET 2, it works fine. This is an acceptable solution for now, but would there be some potential advantage to using a .NET 4 build? Anyone want to take a crack at HyperDescriptor, see why it's so slow with a .NET 4 build?

推荐答案

我下载了源代码代码并使用.NET 4运行测试。有一个令人印象深刻的数值 InvalidOperationException 抛出并被捕获,导致缓慢。

I downloaded the source code and ran the test with .NET 4. There's an impressive number of InvalidOperationException thrown and caught, causing the slowness.

转到 HyperTypeDescriptionProvider.BuildDescriptor 并替换:

[ReflectionPermission(SecurityAction.Assert, Flags = ReflectionPermissionFlag.AllFlags)]

by:

[SecuritySafeCritical]
[ReflectionPermission(SecurityAction.Assert, Unrestricted = true)]

AllFlags已被弃用,仅引起警告,但是从安全透明方法断言在.NET 4中无效。请参见 .NET Framework 4中的安全更改4 了解更多信息

AllFlags is deprecated and only causes a warning, but asserting from a security transparent method isn't valid in .NET 4. See Security Changes in the .NET Framework 4 for more information.

这篇关于HyperDescriptor在内置.NET 4时是否工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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