11using System . Threading . Tasks ;
2+ using ICSharpCode . CodeConverter . Common ;
3+ using ICSharpCode . CodeConverter . CSharp ;
24using ICSharpCode . CodeConverter . Tests . TestRunners ;
35using Xunit ;
46
@@ -914,4 +916,49 @@ public static void LogAndReset(ref int arg)
914916}" ) ;
915917 }
916918
919+ [ Fact ]
920+ public async Task Issue1225_OutAttributeOnParameterFromOtherFileDoesNotCrashAsync ( )
921+ {
922+ // Issue #1225: IsOutAttribute called SemanticModel.GetTypeInfo(attribute) on an attribute node
923+ // that belongs to a different syntax tree (parameter declared in a separate source file).
924+ // This caused ArgumentException "Knoten ist nicht innerhalb Syntaxbaum" /
925+ // "Node is not within syntax tree". The fix falls back to name-based checking
926+ // when the attribute's syntax tree differs from the current semantic model's tree.
927+ var serviceFileContent = @"Imports System.Runtime.InteropServices
928+ Public Class LicenseService
929+ Public Shared ReadOnly Property Instance As LicenseService
930+ Get
931+ Return New LicenseService()
932+ End Get
933+ End Property
934+
935+ Public Function GetLicenseMaybe(<Out> ByRef licenseName As String) As Boolean
936+ licenseName = Nothing
937+ Return False
938+ End Function
939+ End Class" ;
940+
941+ var callerFileContent = @"Public Class Caller
942+ Public Sub Test(licenseName As String)
943+ Dim res = LicenseService.Instance.GetLicenseMaybe(licenseName)
944+ End Sub
945+ End Class" ;
946+
947+ var options = new TextConversionOptions ( DefaultReferences . With ( ) ) { ShowCompilationErrors = true } ;
948+ var languageConversion = new VBToCSConversion { ConversionOptions = options } ;
949+ var serviceTree = languageConversion . CreateTree ( serviceFileContent ) ;
950+ var callerTree = languageConversion . CreateTree ( callerFileContent ) ;
951+
952+ // Add both files to the same project so that the VB compilation sees both
953+ var serviceDoc = await languageConversion . CreateProjectDocumentFromTreeAsync ( serviceTree , options . References ) ;
954+ var callerDoc = serviceDoc . Project . AddDocumentFromTree ( callerTree ) ;
955+
956+ // Convert only the caller document; its parameter info comes from the service file's syntax tree
957+ var result = await ProjectConversion . ConvertSingleAsync < VBToCSConversion > ( callerDoc , options ) ;
958+ var output = ( result . ConvertedCode ?? "" ) + ( result . GetExceptionsAsString ( ) ?? "" ) ;
959+
960+ Assert . DoesNotContain ( "#error" , output ) ;
961+ Assert . Contains ( "GetLicenseMaybe" , output ) ;
962+ }
963+
917964}
0 commit comments