c# - Unhandled Type Exception(System.TypeInitializationException) -
c# - Unhandled Type Exception(System.TypeInitializationException) -
as title says, visual studio throwing exception when execute program. exact error:
an unhandled exception of type 'system.typeinitializationexception' occurred in mscorlib.dll
as i'm rather new using visual studio, , c# matter, unable discern issue was. did google, none of info found assisted recovery of excepted program.
program code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading; using system.threading.tasks; using system.windows.forms; using system.io; namespace game { public struct entity { int xp, hp, mana, luck, strength, defense; float modstrength, moddefense; string stance; } public class game { private entity enemy; private static dictionary<string, int> playerdata = new dictionary<string, int>(); public static string[] entitypool = new streamreader(properties.resources.entities).tostring().split('?'); static void main (string[] args) { instanceplayer(); console.readkey(); } private static void instanceplayer () { string[] playerdatadummy = entitypool[0].trim().split(';'); foreach (string s in playerdatadummy) { string[] indivarr = s.split(' '); playerdata.add(indivarr[0], convert.toint16(indivarr[1])); } foreach (keyvaluepair<string, int> s in playerdata) { console.writeline("[{0}] {1}", s.key, s.value); } } private void instanceenemy () { } } }
i have been able narrow issue downwards line, though...
public static string[] entitypool = new streamreader(properties.resources.entities).tostring().split('?');
that's much i've been found out; removing initialization of that, , it's reference, nullifies issue. alas, need there.
take @ streamreader class on msdn. there several constructors , simple illustration reading text file. i'm not sure have in properties.resources.entities (a file path assume). assuming valid file path or stream , constructor isn't throwing error, creating streamreader calling .tostring() gives string representation of streamreader object, not contents of file or stream. not expecting. sample on msdn page should help using streamreader class.
c# exception visual-studio-2013 streamreader
Comments
Post a Comment