.NET Core App Crashes when loading assemblies

This issue (https://github.com/ServiceStack/Issues/issues/65) allowed me to pinpoint what service was causing my app to crash. This service references more than one service model and for some reason it is claiming that this reference can’t be found.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Starpeer.UserAuth.API.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at ServiceStack.Host.ServiceExecExtensions.<GetActions>d__0.MoveNext() in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/Host/ServiceExec.cs:line 32
   at ServiceStack.Host.ServiceController.RegisterService(ITypeFactory serviceFactoryFn, Type serviceType) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/Host/ServiceController.cs:line 146
   at ServiceStack.Host.ServiceController.Register(ITypeFactory serviceFactoryFn) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/Host/ServiceController.cs:line 134
   at ServiceStack.Host.ServiceController.Init() in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/Host/ServiceController.cs:line 73
   at ServiceStack.ServiceStackHost.Init() in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/ServiceStackHost.cs:line 191
   at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/AppHostBase.NetCore.cs:line 184
   at Starpeer.CallRecording.App.API.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\www\dev\cr\Starpeer.CallRecording.App.API\Starpeer.CallRecording.App.API\Startup.cs:line 32
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Starpeer.CallRecording.App.API.Program.Main(String[] args) in C:\www\dev\cr\Starpeer.CallRecording.App.API\Starpeer.CallRecording.App.API\Program.cs:line 14

The first thing you should check that the assembly Starpeer.UserAuth.API.ServiceModel exists in the bin folder.

The second reason when you can get this error is the case: if you compile one of you dll with reference to one version of Starpeer.UserAuth.API.ServiceModel but in the bin folder you place another version of Starpeer.UserAuth.API.ServiceModel. You should place the same version of Starpeer.UserAuth.API.ServiceModel with which you compiled you libraries.

The third common case when you can get this error: if you use .NET Core 1.0.* SDK with *.csproj project format and try to reference assembly by
<Reference Include="path/to/assembly.dll" />

Referencing assemblies do not work with dotnet run and dotnet exec commands and *.csproj files on older .NET Core SDK version and was fixed only in 2.0-preview. So you should reference packages or projects instead of dlls in *.csproj to avoid FileNotFoundException

The third reason was it, thanks!

For anyone else running into this it’s actually not that hard to setup your own nuget server to fix this