vb.net - Run time errors in code converted from VB to C# -


this question has answer here:

i have piece of code in vb

 private function readprofileviewplotoptions(byval savepath string) profileviewoptionstype             dim filename string             dim filenumber short             dim inint integer             filename = system.io.path.combine(savepath, "cfgpropt.sys")             if not system.io.file.exists(filename)                 readprofileviewplotoptions .viewconcave = cbool(getsetting(my.application.info.title, "profileviewplotoptions", "viewconcave", cstr(1))) ----- 

i converted c# this

private static mold_power_suite.model.frontendstructures.planviewoptionstype readplanviewplotoptions(string savepath)         {             var title = ((assemblytitleattribute)system.reflection.assembly.getexecutingassembly().getcustomattributes(typeof(assemblytitleattribute), false)[0]).title;             mold_power_suite.model.frontendstructures.planviewoptionstype functionreturnvalue = default(mold_power_suite.model.frontendstructures.planviewoptionstype);             string filename = null;             short filenumber = 0;             int inint = 0;             filename = system.io.path.combine(savepath, "cfgplopt.sys");             if (!system.io.file.exists(filename))             {                 functionreturnvalue.viewconcave = convert.toboolean(interaction.getsetting(title, "planviewplotoptions", "viewconcave", convert.tostring(1))); ----- } 

during run-time , code breaking @ line

functionreturnvalue.viewconcave = convert.toboolean(interaction.getsetting(title, "planviewplotoptions", "viewconcave", convert.tostring(1)));

the error shown compiler "format exception unhandled" .string not recognized valid boolean."

where going wrong ?

when setting not found getsetting returns default value of "1", ie string containing value 1. cannot converted bool via convert. last parameter of getsetting must string, either use

convert.toboolean(interaction.getsetting(title, "planviewplotoptions", "viewconcave", convert.tostring(true))); 

or just

convert.toboolean(interaction.getsetting(title, "planviewplotoptions", "viewconcave", "true")); 

Comments