views:

104

answers:

2

I'm trying to obfuscate some VB.NET 2003 app.

The resulting assemblyes are obfuscated and "run" with some errors.

I cleaned all potential reflection problems, but I'm not being able to read the selected value of a combobox.

I load the Combobox using their Datasource properties, using a collection of "VTPair" (a class created by me with 2 properties: one of string type and other of object type to store the value)

This combobox handle pairs like "Male | M" or "Female | F".

When trying to see what is selected, I use if mycombo1.SelectedValue = "M" then

This code, after obfuscation, throws me an exception that cannot cast type "XX" to string "M".

So, I changed the code to something more correct, explicitly casting the selected value to String:

if ctype(mycombo1.SelectedValue,string) = "M" then

But the error is the same.

Debugin my original code, the SelectedValue property is of type "Object" but it is a string.

I tried using the ComboBox.SelectedItem property that is also an object but this time what is inside is of type "VTPair" (my own class) and then trying to access its "Value" property (which is of type Object) and trying to cast to string fails again.

Does anyone have an idea to "translate" this piece of code to work OK after Dotfucate it?

Thanks!

A: 

Not sure of the VB Syntax but in C# I think you would want something where the right-hand side is typeof(MyType). This way the type will be obfuscated to match the renamed type.

No Refunds No Returns
This is very TRUE with Reflection problems. If you use a GetType.ToString() and then compares it... after obfuscation it won't work. But my case is a CAST problem.
Romias
myCombo.SElectedValue.ToString() ?
No Refunds No Returns
+1  A: 

From MSDN:

ListControl.SelectedValue Property: Gets or sets the value of the member property specified by the ValueMember property.

So whatever property NAME you set for the ValueMember property will be used when you use the SelectedValue property. So you may need to exclude from obfuscation, the property which you specify via the ComboBox.ValueMember property.

logicnp
I excluded from obfuscation the entire class with the Text/Value pair and worked. But I never thought about the ValueMember property being the issue. Thanks a lot!
Romias