Does HyperDescriptor work when built in .NET 4?
Asked Answered
S

1

8

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.

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?

Showdown answered 23/6, 2010 at 21:40 Comment(1)
Ooh. Interesting. Will look at this tomorrow if not resolved.Satisfactory
V
13

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.

Go to HyperTypeDescriptionProvider.BuildDescriptor and replace:

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

by:

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

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.

Viral answered 23/6, 2010 at 21:59 Comment(4)
Worked perfectly, timings are super fast again. Thanks!Showdown
Hi @julien, i tried to compile the project in .net 4.5.2, am getting below error. The Deny stack modifier has been obsoleted by the .NET Framework. any fix for this? thanks.Bouncer
also, when i change the version to v4.0, i get error at static void Main() { // verify that things work OK without reflection access new ReflectionPermission(ReflectionPermissionFlag.AllFlags).Deny(); with error The Deny stack modifier has been obsoleted by the .NET Framework.Bouncer
When i change the version to 4.5.2, i got above error. then i commented it and ran the code, it executed fine. but then the output file was blank. even with 4.0, the output file was blank. i went ahead and used the dll and tried to convert a List<t> to datatable. but the table was empty. when i debugged, i below property was coming blank. PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); appreciate any help in this regard. objective is to make it work with .net 4.5.2. thanks in advance.Bouncer

© 2022 - 2024 — McMap. All rights reserved.