@@ -37,17 +37,25 @@ public sealed class FunctionMetadataResolver : MetadataReferenceResolver
3737 "System.Xml" ,
3838 "System.Net.Http" ,
3939 typeof ( object ) . Assembly . Location ,
40- typeof ( TraceWriter ) . Assembly . Location ,
41- typeof ( TimerInfo ) . Assembly . Location ,
42- typeof ( System . Web . Http . ApiController ) . Assembly . Location
40+ typeof ( IAsyncCollector < > ) . Assembly . Location , /*Microsoft.Azure.WebJobs*/
41+ typeof ( JobHost ) . Assembly . Location , /*Microsoft.Azure.WebJobs.Host*/
42+ typeof ( CoreJobHostConfigurationExtensions ) . Assembly . Location , /*Microsoft.Azure.WebJobs.Extensions*/
43+ typeof ( System . Web . Http . ApiController ) . Assembly . Location /*System.Web.Http*/
44+ } ;
45+
46+ private static readonly Assembly [ ] SharedAssemblies =
47+ {
48+ typeof ( Newtonsoft . Json . JsonConvert ) . Assembly /*Newtonsoft.Json*/
4349 } ;
4450
4551 private static readonly string [ ] DefaultNamespaceImports =
4652 {
4753 "System" ,
4854 "System.Collections.Generic" ,
4955 "System.Linq" ,
50- "System.Net.Http"
56+ "System.Net.Http" ,
57+ "Microsoft.Azure.WebJobs" ,
58+ "Microsoft.Azure.WebJobs.Host"
5159 } ;
5260
5361 public FunctionMetadataResolver ( FunctionMetadata metadata , TraceWriter traceWriter )
@@ -109,20 +117,42 @@ public override ImmutableArray<PortableExecutableReference> ResolveReference(str
109117 {
110118 return ImmutableArray < PortableExecutableReference > . Empty ;
111119 }
120+
112121 if ( ! HasValidAssemblyFileExtension ( reference ) )
113122 {
114- var result = _scriptResolver . ResolveReference ( reference , baseFilePath , properties ) ;
123+ // Try to resolve using the default resolver (framework assemblies, e.g. System.Core, System.Xml, etc.)
124+ ImmutableArray < PortableExecutableReference > result = _scriptResolver . ResolveReference ( reference , baseFilePath , properties ) ;
125+
126+ // If the default script resolver can't resolve the assembly
127+ // check if this is one of host's shared assemblies
128+ if ( result . IsEmpty )
129+ {
130+ Assembly assembly = SharedAssemblies
131+ . FirstOrDefault ( m => string . Compare ( m . GetName ( ) . Name , reference , StringComparison . OrdinalIgnoreCase ) == 0 ) ;
132+
133+ if ( assembly != null )
134+ {
135+ result = ImmutableArray . Create ( MetadataReference . CreateFromFile ( assembly . Location ) ) ;
136+ }
137+ }
115138
116139 return result ;
117140 }
118141
142+ return GetMetadataFromReferencePath ( reference ) ;
143+ }
144+
145+ private ImmutableArray < PortableExecutableReference > GetMetadataFromReferencePath ( string reference )
146+ {
119147 if ( Path . IsPathRooted ( reference ) )
120148 {
149+ // If the path is rooted, create a direct reference to the assembly file
121150 return ImmutableArray . Create ( MetadataReference . CreateFromFile ( reference ) ) ;
122151 }
123- else if ( reference . StartsWith ( CSharpConstants . PrivateAssembliesFolderName + " \\ " , StringComparison . OrdinalIgnoreCase ) )
152+ else
124153 {
125- string filePath = Path . Combine ( _privateAssembliesPath , Path . GetFileName ( reference ) ) ;
154+ // Treat the reference as a private assembly reference
155+ string filePath = Path . Combine ( _privateAssembliesPath , reference ) ;
126156 if ( File . Exists ( Path . Combine ( filePath ) ) )
127157 {
128158 return ImmutableArray . Create ( MetadataReference . CreateFromFile ( filePath ) ) ;
0 commit comments