Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
fixed issue with dependency loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Goncalo Oliveira committed Nov 25, 2020
1 parent fc53b25 commit be71fa4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN dotnet restore
COPY src/. .

# build and publish
RUN dotnet publish -c release -o published faas-run.csproj
RUN dotnet publish -c release -r linux-x64 --no-self-contained /p:PublishSingleFile=true -o published faas-run.csproj

# stage 2
FROM mcr.microsoft.com/dotnet/aspnet:5.0
Expand Down
6 changes: 3 additions & 3 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

# osx x64
echo "Publishing OSX x64..."
dotnet publish -c release -o published -r osx-x64 src/faas-run.csproj
dotnet publish -c release --no-self-contained /p:PublishSingleFile=true -o published -r osx-x64 src/faas-run.csproj
zip -r -j published/faas-run-osx-x64.zip published/faas-run

# windows x64
echo "Publishing Windows x64..."
dotnet publish -c release -o published -r win10-x64 src/faas-run.csproj
dotnet publish -c release --no-self-contained /p:PublishSingleFile=true -o published -r win10-x64 src/faas-run.csproj
zip -r -j published/faas-run-win10-x64.zip published/faas-run.exe

# linux x64
echo "Publishing Linux x64..."
dotnet publish -c release -o published -r linux-x64 src/faas-run.csproj
dotnet publish -c release --no-self-contained /p:PublishSingleFile=true -o published -r linux-x64 src/faas-run.csproj
zip -r -j published/faas-run-linux-x64.zip published/faas-run
16 changes: 9 additions & 7 deletions src/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public AssemblyResolver( string path )
packagesPath = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.UserProfile ), ".nuget/packages/" );

// load main assembly
var assemblyPath = Path.Combine( Environment.CurrentDirectory, path );
var assemblyPath = Path.GetFullPath( path );
Assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath( assemblyPath );

Console.WriteLine( $"Loaded function assembly '{path}'." );
Console.WriteLine( $"Loaded function assembly {path}." );

dependencyContext = DependencyContext.Load( Assembly );
resolver = new CompositeCompilationAssemblyResolver(
new ICompilationAssemblyResolver[]
{
new AppBaseCompilationAssemblyResolver( Path.GetDirectoryName( path ) ),
new AppBaseCompilationAssemblyResolver( Path.GetDirectoryName( assemblyPath ) ),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver()
} );
Expand Down Expand Up @@ -83,9 +83,11 @@ private Assembly OnResolving( AssemblyLoadContext context, AssemblyName name )

if (assemblies.Count > 0)
{
Console.WriteLine( $"Loaded dependency '{assemblies[0]}'." );
var dependency = loadContext.LoadFromAssemblyPath(assemblies[0]);

return loadContext.LoadFromAssemblyPath(assemblies[0]);
Console.WriteLine( $"Loaded dependency {assemblies[0]}." );

return ( dependency );
}
}

Expand All @@ -95,9 +97,9 @@ private Assembly OnResolving( AssemblyLoadContext context, AssemblyName name )

try
{
Console.WriteLine( $"Loaded dependency '{Path.GetFileName( path )}'." );
var dependency = loadContext.LoadFromAssemblyPath( path );

return loadContext.LoadFromAssemblyPath( path );
Console.WriteLine( $"Loaded dependency {Path.GetFileName( path )}." );
}
catch ( Exception ex )
{
Expand Down
7 changes: 7 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static void Main(string[] args)
Console.WriteLine("OpenFaaS ASPNET Function Loader");
Console.WriteLine();

//AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

parsed.WithParsed( options =>
{
if ( options.Detach )
Expand Down Expand Up @@ -87,5 +89,10 @@ public static IHostBuilder CreateHostBuilder( string[] args, Options options ) =
webBuilder.UseUrls( $"http://*:{options.Port}" );
} );

private static void OnAssemblyLoad( object sender, AssemblyLoadEventArgs args )
{
System.Diagnostics.Trace.WriteLine( "loaded " + args.LoadedAssembly.GetName().Name );
}
}
}
9 changes: 4 additions & 5 deletions src/faas-run.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<Version>1.1</Version>
<Version>1.2</Version>
<Authors>Goncalo Oliveira</Authors>
<Company>RedPanda Ltd</Company>
<Description>FaaS runner for ASPNET functions</Description>
Expand All @@ -17,8 +14,10 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
<PackageReference Include="Redpanda.OpenFaaS.Functions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="Redpanda.OpenFaaS.Functions" Version="1.1.0" />
</ItemGroup>

</Project>

0 comments on commit be71fa4

Please sign in to comment.