473,287 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Unable to generate code for a value of type...

Reposted from aspnet.buildingcontrols:
Ok, I've got a bunch of derived controls that all have a property Rights of
type Rights (Rights is an Enumerator). I wrote a custom TypeConverter so
that I can use comma separated values in design-time. The TypeConverter
works great in design-time. It converts to and from just fine... However,
when I try to load any page in the site now I get the following error
(Following the error is code for the TypeConverter:

Exception Details: System.Web.HttpException: Unable to generate code for a
value of type 'Intranet.CustomControls.Rights'. This error occurred while
trying to generate the property value for Rights.

Stack Trace:

[HttpException (0x80004005): Unable to generate code for a value of type
'Intranet.CustomControls.Rights'. This error occurred while trying to
generate the property value for Rights.]

System.Web.Compilation.CodeDomUtility.GenerateExpr essionForValue(PropertyInf
o propertyInfo, Object value, Type valueType) +2253

System.Web.Compilation.TemplateControlCompiler.Bui ldBuildMethod(ControlBuild
er builder, Boolean fTemplate, PropertySetterEntry pse) +2538

System.Web.Compilation.TemplateControlCompiler.Bui ldSourceDataTreeFromBuilde
r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +794

System.Web.Compilation.TemplateControlCompiler.Bui ldSourceDataTreeFromBuilde
r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +352

System.Web.Compilation.TemplateControlCompiler.Bui ldSourceDataTreeFromBuilde
r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +352
System.Web.Compilation.TemplateControlCompiler.Bui ldMiscClassMembers()
+51
System.Web.Compilation.PageCompiler.BuildMiscClass Members() +10
System.Web.Compilation.BaseCompiler.BuildSourceDat aTree() +1276
System.Web.Compilation.BaseCompiler.GetCompiledTyp e() +129
System.Web.UI.PageParser.CompileIntoType() +59
System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation() +126

Following is the code for my TypeConverter:

Public Class RightsConverter
Inherits TypeConverter
Public Overloads Overrides Function ConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object) As Object
If IsNothing(value) Then
Return 0
End If
Dim x As String
If value.GetType Is GetType(String) Then
Dim data As String = CStr(value)
Dim r As Rights
r = CType([Enum].Parse(GetType(Rights), data), Rights)
Return r
End If
End Function

Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
If Not IsNothing(value) Then
If Not value.GetType Is GetType(Rights) Then
Throw New ArgumentException("Invalid Rights Enum", "value")
End If
End If
If destinationType Is GetType(String) Then
If IsNothing(value) Then
Return String.Empty
End If

Dim r As Rights = CType(value, Rights)
Dim rVal As String
Dim sa() As String
Dim name As String
Dim i As Integer
For Each name In [Enum].GetNames(GetType(Rights))
i = [Enum].Parse(GetType(Rights), name)
If (i And r) > 0 Then
If IsNothing(sa) Then
ReDim sa(0)
sa(0) = name
Else
ReDim Preserve sa(sa.Length)
sa(sa.GetUpperBound(0)) = name
End If
End If
Next
If Not IsNothing(sa) Then
For i = 0 To sa.GetUpperBound(0)
If i > 0 Then
rVal &= ", " & sa(i)
Else
rVal = sa(i)
End If
Next
Return rVal
Else
Return ""
End If
End If
End Function

Public Overloads Overrides Function CanConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As
System.Type) As Boolean
If sourceType Is GetType(String) Then
Return True
ElseIf sourceType Is GetType(Integer) Then
Return True
Else
MyBase.CanConvertFrom(context, sourceType)
End If
End Function

Public Overloads Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
If destinationType Is GetType(String) Then
Return True
ElseIf destinationType Is GetType(Integer) Then
Return True
Else
MyBase.CanConvertFrom(context, destinationType)
End If
End Function
End Class
Here is what the property looks like on the controls:

<Description("The rights required to view this control."), _
Editor(GetType(RightsEditor), GetType(UITypeEditor)),
DefaultValue("Everyone")> _
Public Property Rights() As Rights
Get
Return _rights
End Get
Set(ByVal Value As Rights)
_rights = Value
End Set
End Property

Anyone have any ideas as to what could be wrong?
Nov 18 '05 #1
4 2527
As an update:
I changed the CanConvertTo so that it will return True for an
InstanceDescriptor and then messed around with some code to create an
InstanceDescriptor in the ConvertTo function:

If destinationType Is GetType(InstanceDescriptor) Then
Dim mi As MethodInfo = GetType([Enum]).GetMethod("Parse", New
Type() {GetType(Type), GetType(String)})

Dim r As Rights = CType(value, Rights)
Dim id As New InstanceDescriptor(mi, New Object()
{GetType(Rights), r.ToString})
Return id
End If

Now when I load the page I get an Object reference not set to an instance of
an object error. I know for sure that the InstanceDescriptor can be used to
create an instance of the Rights enum, as I tested it by using Invoke so I'm
confused as to why this doesn't work.

I also realize that using an InstanceDescriptor isn't the way I should
really be going since this is an enum and doesn't have a parameterized
constructor or anything, but I can't think of anything else. Any thoughts?

Nov 18 '05 #2
Hi Chris,

I got same error when I tested your code. Anyway, the problem disappeared
after I change your property name:

<Description("The rights required to view this control."), _
Editor(GetType(RightsEditor), GetType(UITypeEditor)),
DefaultValue("Everyone")> _
Public Property MyRights() As Rights
Get
Return _rights
End Get
Set(ByVal Value As Rights)
_rights = Value
End Set
End Property

I may test this in your actual code to see if it will work.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hmm.. I tried that with one of my controls but the only thing that changed
was the error message:
Unable to generate code for a value of type
'Intranet.CustomControls.Rights'. This error occurred while trying to
generate the property value for DisplayRights.

I take it you're looking at the sample I put together for Michael? Has this
worked with that sample?

"MSFT" <lu******@online.microsoft.com> wrote in message
news:lf*************@cpmsftngxa06.phx.gbl...
Hi Chris,

I got same error when I tested your code. Anyway, the problem disappeared
after I change your property name:

<Description("The rights required to view this control."), _
Editor(GetType(RightsEditor), GetType(UITypeEditor)),
DefaultValue("Everyone")> _
Public Property MyRights() As Rights
Get
Return _rights
End Get
Set(ByVal Value As Rights)
_rights = Value
End Set
End Property

I may test this in your actual code to see if it will work.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
For posterity's sake:
This turned out to be a bug in the 1.1 framework. There a KB article about
it here: http://support.microsoft.com/default...b;en-us;825082

"Chris Bower" <ch***********@SPAMunionfedbank.com> wrote in message
news:ek*************@TK2MSFTNGP11.phx.gbl...
Hmm.. I tried that with one of my controls but the only thing that changed
was the error message:
Unable to generate code for a value of type
'Intranet.CustomControls.Rights'. This error occurred while trying to
generate the property value for DisplayRights.

I take it you're looking at the sample I put together for Michael? Has this worked with that sample?

"MSFT" <lu******@online.microsoft.com> wrote in message
news:lf*************@cpmsftngxa06.phx.gbl...
Hi Chris,

I got same error when I tested your code. Anyway, the problem disappeared after I change your property name:

<Description("The rights required to view this control."), _
Editor(GetType(RightsEditor), GetType(UITypeEditor)),
DefaultValue("Everyone")> _
Public Property MyRights() As Rights
Get
Return _rights
End Get
Set(ByVal Value As Rights)
_rights = Value
End Set
End Property

I may test this in your actual code to see if it will work.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3,...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
0
by: Steven Bolard | last post by:
Hello, I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am trying to get my webservices to run and although i can compile them and and get wsdl and service descriptions...
4
by: Abi | last post by:
We able to generate this error in our test environment and were able to research this enough to understand that the issue is NOT with an abject that needs to be serialized but rather as the stack...
1
by: Martin Plechsmid | last post by:
Hello, (After investigating my real problem) I've got a C# web service containing a single method: public MyBDO Test() { return null; }
82
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure...
1
by: Markw | last post by:
Hi folks I think I've got a variable problem but not 100% sure. Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.