0

I have a .NET Core command line application which I have deployed as a webjob to Azure.
When I try to access a database in the app I get the following error message:

[10/05/2016 06:23:27 > 5c77b6: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. (Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)) ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Data.SqlClient.SqlConnection.Open()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at CommerceVision.InteractivePurchasingModule.Workflow.DuplicateCheckWorkflowProcessor.<GetUnProcessedEmails>d__4.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at CommerceVision.InteractivePurchasingModule.Workflow.DuplicateCheckWorkflowStep.<Process>d__7.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at CommerceVision.InteractivePurchasingModule.Workflow.WorkflowEngine.<Execute>d__3.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ] --- End of stack trace from previous location where exception was thrown ---
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at CommerceVision.IpWorkflowProcessor.Program.<>c.<<ConfigureApplication>b__19_2>d.MoveNext()
[10/05/2016 06:23:27 > 5c77b6: ERR ]    --- End of inner exception stack trace ---
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
[10/05/2016 06:23:27 > 5c77b6: ERR ]    at CommerceVision.IpWorkflowProcessor.Program.Main(String[] args)


Not sure if anyone else has had the same issue and found a workaround or fix for it. I have been trying to fix this for the past 2 days with no success.
Thanks.

Nathangrad
  • 1,426
  • 10
  • 25
Alex
  • 642
  • 5
  • 16

2 Answers2

1

Ok, I found the problem. There were 2 issues.

1.You need to make sure you have the following in Project.json:

"Microsoft.NETCore.App": {
        "version": "1.0.0",
        "type": "platform"
    },

Mine did not have the "type": "platform" part.

  1. The main thing is you need to have a file named run.cmd in root of your project and include it in your publish output as well:

    @echo off dotnet NameOfYourProject.dll process

Everything worked fine after these changes. Hopefuly this will help other people and save their time.

Alex
  • 642
  • 5
  • 16
0

Similar to me, I changed.

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }

To.

"frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.1.0",
          "type": "platform"
        }
      }
    }
  },
CountZero
  • 6,171
  • 3
  • 46
  • 59