@@ -37,17 +37,25 @@ public sealed class FunctionMetadataResolver : MetadataReferenceResolver
37
37
"System.Xml" ,
38
38
"System.Net.Http" ,
39
39
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*/
43
49
} ;
44
50
45
51
private static readonly string [ ] DefaultNamespaceImports =
46
52
{
47
53
"System" ,
48
54
"System.Collections.Generic" ,
49
55
"System.Linq" ,
50
- "System.Net.Http"
56
+ "System.Net.Http" ,
57
+ "Microsoft.Azure.WebJobs" ,
58
+ "Microsoft.Azure.WebJobs.Host"
51
59
} ;
52
60
53
61
public FunctionMetadataResolver ( FunctionMetadata metadata , TraceWriter traceWriter )
@@ -109,20 +117,42 @@ public override ImmutableArray<PortableExecutableReference> ResolveReference(str
109
117
{
110
118
return ImmutableArray < PortableExecutableReference > . Empty ;
111
119
}
120
+
112
121
if ( ! HasValidAssemblyFileExtension ( reference ) )
113
122
{
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
+ }
115
138
116
139
return result ;
117
140
}
118
141
142
+ return GetMetadataFromReferencePath ( reference ) ;
143
+ }
144
+
145
+ private ImmutableArray < PortableExecutableReference > GetMetadataFromReferencePath ( string reference )
146
+ {
119
147
if ( Path . IsPathRooted ( reference ) )
120
148
{
149
+ // If the path is rooted, create a direct reference to the assembly file
121
150
return ImmutableArray . Create ( MetadataReference . CreateFromFile ( reference ) ) ;
122
151
}
123
- else if ( reference . StartsWith ( CSharpConstants . PrivateAssembliesFolderName + " \\ " , StringComparison . OrdinalIgnoreCase ) )
152
+ else
124
153
{
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 ) ;
126
156
if ( File . Exists ( Path . Combine ( filePath ) ) )
127
157
{
128
158
return ImmutableArray . Create ( MetadataReference . CreateFromFile ( filePath ) ) ;
0 commit comments