Trying to compile a script at runtime
im trying to compile a script at runtime using CSharpCompilation.Emit
this is the script i want to compile
certainly it would be a lot better to actually use source generators, however my project requires the ability to generate code from scripts that are also compiled at runtime. however this specific script is causing me errors that i cant seem to find. errors like switch statments missing, commas missing, semicolons missing, and like 200 of these, so i really have no idea
i hope someone here has some ideas of what i could do. i already tried restarting visual studio, that didnt work
2 Replies
these are all the diagnostics
(28,1): error CS1733: Expected expression
(27,1): error CS1733: Expected expression
(43,1): error CS1733: Expected expression
(27,1): error CS1733: Expected expression
(28,1): error CS1733: Expected expression
(28,1): error CS1002: ; expected
(28,1): error CS1002: ; expected
(43,1): error CS1002: ; expected
(29,1): error CS1513: } expected
(29,1): error CS1513: } expected
(44,1): error CS1513: } expected
(31,1): error CS1525: Invalid expression term '}'
(31,1): error CS1525: Invalid expression term '}'
(46,1): error CS1525: Invalid expression term '}'
(27,1): error CS1002: ; expected
(28,1): error CS1513: } expected
(30,1): error CS1525: Invalid expression term '}'
(27,1): error CS1002: ; expected
(28,1): error CS1513: } expected
(30,1): error CS1525: Invalid expression term '}'
(31,1): error CS1002: ; expected
(33,1): error CS1733: Expected expression
(31,1): error CS1002: ; expected
(33,1): error CS1002: ; expected
(34,1): error CS1513: } expected
(35,1): error CS1514: { expected
(46,1): error CS1002: ; expected
(35,1): error CS1513: } expected
(33,1): error CS1733: Expected expression
(36,1): error CS1513: } expected
(33,1): error CS1002: ; expected
(30,1): error CS1002: ; expected
(48,1): error CS1733: Expected expression
(32,1): error CS1733: Expected expression
(30,1): error CS1002: ; expected
(36,1): error CS1003: Syntax error, 'switch' expected
(34,1): error CS1513: } expected
(48,1): error CS1002: ; expected
(32,1): error CS1002: ; expected
(37,1): error CS1513: } expected
(49,1): error CS1513: } expected
(35,1): error CS1514: { expected
(33,1): error CS1513: } expected
(32,1): error CS1733: Expected expression
(35,1): error CS1513: } expected
(32,1): error CS1002: ; expected
(39,1): error CS1003: Syntax error, 'switch' expected
(50,1): error CS1514: { expected
(34,1): error CS1514: { expected
(36,1): error CS1513: } expected
(33,1): error CS1513: } expected
(50,1): error CS1513: } expected
(34,1): error CS1513: } expected
(40,1): error CS1513: } expected
(36,1): error CS1003: Syntax error, 'switch' expected
(51,1): error CS1513: } expected
(35,1): error CS1513: } expected
(34,1): error CS1514: { expected
(42,1): error CS1003: Syntax error, 'switch' expected
(37,1): error CS1513: } expected
(51,1): error CS1003: Syntax error, 'switch' expected
(34,1): error CS1513: } expected
(35,1): error CS1003: Syntax error, 'switch' expected
(43,1): error CS1513: } expected
(39,1): error CS1003: Syntax error, 'switch' expected
(52,1): error CS1513: } expected
(35,1): error CS1513: } expected
(36,1): error CS1513: } expected
(45,1): error CS1525: Invalid expression term '}'
(40,1): error CS1513: } expected
(35,1): error CS1003: Syntax error, 'switch' expected
(54,1): error CS1003: Syntax error, 'switch' expected
(38,1): error CS1003: Syntax error, 'switch' expected
(36,1): error CS1513: } expected
(55,1): error CS1513: } expected
(45,1): error CS1002: ; expected
(42,1): error CS1003: Syntax error, 'switch' expected
(39,1): error CS1513: } expected
(57,1): error CS1003: Syntax error, 'switch' expected
(38,1): error CS1003: Syntax error, 'switch' expected
(43,1): error CS1513: } expected
(46,1): error CS1525: Invalid expression term '}'
(41,1): error CS1525: Invalid expression term '}'
(58,1): error CS1513: } expected
(39,1): error CS1513: } expected
(46,1): error CS1002: ; expected
(45,1): error CS1525: Invalid expression term '}'
(41,1): error CS1002: ; expected
(60,1): error CS1003: Syntax error, 'switch' expected
(41,1): error CS1525: Invalid expression term '}'
(45,1): error CS1002: ; expected
(41,1): error CS1002: ; expected
(61,1): error CS1513: } expected
(42,1): error CS1525: Invalid expression term '}'
(46,1): error CS1525: Invalid expression term '}'
(42,1): error CS1525: Invalid expression term '}'
(63,1): error CS1003: Syntax error, 'switch' expected
(46,1): error CS1002: ; expected
(42,1): error CS1002: ; expected
(42,1): error CS1002: ; expected
(64,1): error CS1513: } expected
(66,1): error CS1003: Syntax error, 'switch' expected
(67,1): error CS1513: } expected
(69,1): error CS1003: Syntax error, 'switch' expected
(70,1): error CS1513: } expected
(72,1): error CS1003: Syntax error, 'switch' expected
(73,1): error CS1513: } expected
(75,1): error CS1003: Syntax error, 'switch' expected
(76,1): error CS1513: } expected
(78,1): error CS1003: Syntax error, 'switch' expected
(79,1): error CS1513: } expected
(81,1): error CS1003: Syntax error, 'switch' expected
(82,1): error CS1513: } expected
(84,1): error CS1003: Syntax error, 'switch' expected
(85,1): error CS1513: } expected
(87,1): error CS1003: Syntax error, 'switch' expected
(88,1): error CS1513: } expected
(90,1): error CS1003: Syntax error, 'switch' expected
(91,1): error CS1513: } expected
(93,1): error CS1003: Syntax error, 'switch' expected
(94,1): error CS1513: } expected
(96,1): error CS1003: Syntax error, 'switch' expected
(97,1): error CS1513: } expected
(99,1): error CS1003: Syntax error, 'switch' expected
(100,1): error CS1513: } expected
(102,1): error CS1525: Invalid expression term '}'
(102,1): error CS1002: ; expected
(103,1): error CS1525: Invalid expression term '}'
(103,1): error CS1002: ; expected
Have you looked at the script in an editor like VS or VSCode?
Cleaning up the formatting will probably also help