@@ -154,20 +154,24 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
154154
155155 public static async Task < string ? > GetMetadataFileContents ( ToolkitSampleMetadata metadata , string fileExtension )
156156 {
157- var filePath = GetPathToFileWithoutExtension ( metadata . SampleControlType ) ;
157+ var filePath = GetRelativePathToFileWithoutExtension ( metadata . SampleControlType ) ;
158158
159159 try
160160 {
161- var file = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( $ "{ filePath } .{ fileExtension . Trim ( '.' ) } ") ) ;
162- var textContents = await FileIO . ReadTextAsync ( file ) ;
161+ // Workaround for https://github.com/unoplatform/uno/issues/8649
162+ if ( fileExtension . Contains ( ".cs" ) )
163+ {
164+ fileExtension = fileExtension . Replace ( ".cs" , ".cs.dat" ) ;
165+ }
163166
164- // Remove toolkit attributes
165- textContents = Regex . Replace ( textContents , @$ "\s+?\[{ nameof ( ToolkitSampleAttribute ) . Replace ( "Attribute" , "" ) } .+\]", "" ) ;
166- textContents = Regex . Replace ( textContents , @$ "\s+?\[{ nameof ( ToolkitSampleOptionsPaneAttribute ) . Replace ( "Attribute" , "" ) } .+\]", "" ) ;
167+ var finalPath = $ "ms-appx:///{ filePath } .{ fileExtension . Trim ( '.' ) } ";
168+
169+ var file = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( $ "ms-appx:///{ filePath } .{ fileExtension . Trim ( '.' ) } ") ) ;
170+ var textContents = await FileIO . ReadTextAsync ( file ) ;
167171
168172 return textContents ;
169173 }
170- catch ( Exception )
174+ catch
171175 {
172176 return null ;
173177 }
@@ -177,7 +181,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
177181 /// Compute path to a code file bundled in the app using type information.
178182 /// Assumes file path in project matches namespace.
179183 /// </summary>
180- public static string GetPathToFileWithoutExtension ( Type type )
184+ private static string GetRelativePathToFileWithoutExtension ( Type type )
181185 {
182186 var simpleAssemblyName = type . Assembly . GetName ( ) . Name ;
183187 var typeNamespace = type . Namespace ;
@@ -188,9 +192,11 @@ public static string GetPathToFileWithoutExtension(Type type)
188192 if ( string . IsNullOrWhiteSpace ( typeNamespace ) )
189193 throw new ArgumentException ( $ "Unable to find namespace for provided type { type } .", nameof ( typeNamespace ) ) ;
190194
195+ var sampleName = simpleAssemblyName . Replace ( ".Sample" , "" ) ;
196+
191197 var folderPath = typeNamespace . Replace ( simpleAssemblyName , "" ) . Trim ( '.' ) . Replace ( '.' , '/' ) ;
192198
193- return $ "ms-appx:// /{ simpleAssemblyName } /{ folderPath } /{ type . Name } ";
199+ return $ "SourceAssets/ { sampleName } /samples /{ simpleAssemblyName } /{ folderPath } /{ type . Name } ";
194200 }
195201 }
196202}
0 commit comments