@@ -215,6 +215,7 @@ private ExcisionStats ProcessCodeFile(string fileName, string inputPath, EExcisi
215215 if ( currentScope . StartIndex == - 1
216216 || currentScope . StopIndex == - 1
217217 || InjectedMacroAlreadyExistsAtLocation ( answerText , currentScope . StartIndex , true , excisionLanguage . ServerScopeStartString )
218+ || InjectedMacroAlreadyExistsAtLocation ( answerText , currentScope . StartIndex , false , excisionLanguage . ServerScopeStartString )
218219 || InjectedMacroAlreadyExistsAtLocation ( answerText , currentScope . StopIndex , false , excisionLanguage . ServerScopeEndString ) )
219220 {
220221 continue ;
@@ -230,14 +231,22 @@ private ExcisionStats ProcessCodeFile(string fileName, string inputPath, EExcisi
230231 // Next we must add dummy reference variables if they exist.
231232 foreach ( KeyValuePair < int , HashSet < string > > dummyRefDataPair in visitor . ClassStartIdxDummyReferenceData )
232233 {
233- var dummyRefDataBlockString = new StringBuilder ( "#ifndef " + excisionLanguage . ServerPrecompilerSymbol ) ;
234+ var dummyRefDataBlockString = new StringBuilder ( ) ;
235+ var dummyVarScope = "#ifndef " + excisionLanguage . ServerPrecompilerSymbol ;
236+ dummyRefDataBlockString . Append ( dummyVarScope ) ;
234237 foreach ( var dummyVarDef in dummyRefDataPair . Value )
235238 {
236239 dummyRefDataBlockString . Append ( "\r \n \t " + dummyVarDef ) ;
237240 }
238241
239242 dummyRefDataBlockString . Append ( "\r \n " + excisionLanguage . ServerScopeEndString + "\r \n " ) ;
240243
244+ // If there is already a block of dummy reference variables we skip adding new ones, there is no guarantee we are adding the right code.
245+ if ( InjectedMacroAlreadyExistsAtLocation ( answerText , dummyRefDataPair . Key , false , dummyVarScope + "\r \n " ) )
246+ {
247+ continue ;
248+ }
249+
241250 serverCodeInjections . Add ( new KeyValuePair < int , string > ( dummyRefDataPair . Key , dummyRefDataBlockString . ToString ( ) ) ) ;
242251 }
243252 }
0 commit comments