Can you use project.json in an azure service fabric project? - azure

I'm trying to use project.json to make managing packages easier in a Service Fabric project.
However it is failing and I think it is due to not including ServiceFabricServiceModel.dll in the services. I can see the dll in the nuget packages in C:\Users\nick.nuget\packages\Microsoft.ServiceFabric.Actors\2.0.135\lib\net45, but the nuspec file does not reference it.
There are quite a few errors when trying to deploy.
For example
Exception thrown during async task execution
System.IO.FileNotFoundException: Could not load file or assembly 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Microsoft.ServiceFabric.Services.Common.FabricServiceConfigSection.Initialize()
at Microsoft.ServiceFabric.Services.Remoting.FabricTransport.FabricTransportServiceRemotingProviderAttribute.CreateServiceRemotingListener(ServiceContext serviceContext, IService service)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<OpenCommunicationListenersAsync>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<System.Fabric.IStatefulServiceReplica.ChangeRoleAsync>d__5.MoveNext()
=== Pre-bind state information ===
LOG: DisplayName = ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/SfDevCluster/Data/_App/_Node_1/SceneSkopePlatformType_App0/ServiceRegistrationServicePkg.Code.1.1.13 (2016-04-05 16.10.16Z)/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.ServiceFabric.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SfDevCluster\Data\_App\_Node_1\SceneSkopePlatformType_App0\ServiceRegistrationServicePkg.Code.1.1.13 (2016-04-05 16.10.16Z)\ServiceRegistrationService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: ServiceFabricServiceModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

This is a breaking change how dotnet cli handles not listed assemblies in nuget packages. For "old style" projects VS2015 copies this assembly to the project output, but the dotnet cli does not.
Until it's fixed, you can either wrap the assembly or copy it to the output in a postpublish step.
The assembly is downloaded to:
%userprofile%.nuget\packages\Microsoft.ServiceFabric.Services\2.0.135\lib\net45

MSFT solved this in the latest nuget package version 2.1.150

Related

How to resolve following issue : 'Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' error

getting this issue for crystal report: 'System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'...i have added log4net.dll on azure server via filezilla...
what steps to be done to resolve this issue

How can I resolve this NewtonSoft version conflict?

I'm working on an Azure function. I'm using Microsoft.Azure.Devices.Shared, which requires NewtonSoft v11, so I've implemented some manual binding redirects with the app domain which seems to be working (see below). But somehow, there is a hard reference to the WebJob app domain that NewtonSoft is conflicting with if I'm reading the log below correctly:
2018-05-21T22:03:03.824 [Info] Exception:
[A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadNeither' in a byte array.
My Newtonsoft v11 dll is in the function's bin directory and is referenced there like so:
#r "bin\Newtonsoft.Json.dll"
There is actual code in the function that works correctly in the function:
dynamic eventHubMessage =
JsonConvert.DeserializeObject<JObject>(myEventHubMessage);
But when it hits this line:
CRSLTwinData twinData = IotHubProxy.GetTwinData(hubDeviceId);
It throws the exception. The reference to M.A.D.Shared and Newtonsoft 11 is therein.
I've tried everything I can to get the function to use the 11 version of the dll, but something is obviously out of whack.
UPDATE: we tried redirecting to 9 instead and got this:
2018-05-22T13:24:48.336 [Info] Exception: [A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadFrom' at location 'D:\local\Temporary ASP.NET
Files\root\e801054b\3f30c00f\assembly\dl3\e5381214\00f64e9a_9af1d301\Newtonsoft.Json.dll'.
Then we tried redirect to 10 and got this :):
2018-05-22T14:16:14.509 [Info] Exception:
[A]Newtonsoft.Json.Linq.JObject cannot be cast to
[B]Newtonsoft.Json.Linq.JObject. Type A originates from
'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location
'D:\Program Files
(x86)\SiteExtensions\Functions\1.0.11702\bin\Newtonsoft.Json.dll'.
Type B originates from 'Newtonsoft.Json, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context
'LoadFrom' at location 'D:\local\Temporary ASP.NET
Files\root\e801054b\3f30c00f\assembly\dl3\e5381214\00f64e9a_9af1d301\Newtonsoft.Json.dll'.
I presume you are using azure function 1.0 which has known assembly resolution problem.
Since webjob use strict version number of Newtonsoft json, what I have done in my project is to downgrade all mine to inline with the sdk's
Use Microsoft.NET.Sdk.Functions version 1.0.13, which consumes Newtonsoft.Json 10.0.3

Is it possible to reference external assembly with native dependencies in Azure function?

I'm getting following exception when doing aforementioned:
2017-12-10T12:40:39.771 Exception during runtime resolution of assembly 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null':
'System.IO.FileLoadException: Could not load file or assembly 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019)
File name: 'Affdex, Version=3.4.1.1320, Culture=neutral, PublicKeyToken=null' ---> System.IO.FileLoadException: Attempt to load an unverifiable executable with fixups
Is there a location that Azure Function runtime looks for dependencies (like Sys32/Inetsrv in Windows)?

Server Error in '/' Application. Could not load file or assembly 'System.Web.WebPages.Deployment, Version=3.0.0.0,

Server Error in '/' Application.
Could not load file or assembly 'System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +0
System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +89
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2053.0
Go to the references find the system. Web.webpages.deployment then go to the properties then check the version and then insert in to Web config file
I hope it helps.

Failing to load ServiceBus Assembly when debugging

I am implementing azure service bus functionality into a clients asp.net webforms solution.
a worker role polls the bus periodically for new messages, and a web role is defined for the existing webforms app, which is responsible for adding putting messages on the bus queue.
Whenever i try to run the app locally i get an error due to the Microsoft.ServiceBus assembly being a mismatch from the expected...
System.IO.FileLoadException was unhandled
HResult=-2146234304
Message=Could not load file or assembly 'Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=Azure.EnquiryWorker
FileName=Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog==== Pre-bind state information ===
LOG: User = *Omitted*
LOG: DisplayName = Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Users/*path omitted*/*project name omitted*/csx/Debug/roles/Azure.EnquiryWorker/approot
LOG: Initial PrivatePath = C:\Users\*path omitted*/*project name omitted*\csx\Debug\roles\Azure.EnquiryWorker\approot
Calling assembly : Azure.EnquiryWorker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\*path omitted*/*project name omitted*\csx\Debug\roles\Azure.EnquiryWorker\approot\Azure.EnquiryWorker.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/*path omitted*/*project name omitted*/csx/Debug/roles/Azure.EnquiryWorker/approot/Microsoft.ServiceBus.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
StackTrace:
at Azure.EnquiryWorker.WorkerRole.OnStart()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRole(RoleType roleType)
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<InitializeRole>b__0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
The webforms app has the serviceBus dll in the bin folder (which is added as an indirect reference, as the service bus code resides in a library project).
The GAC contains no servicebus assemblies, my projects are all referencing v2 of the servicebus dll, and are set to CopyLocal.
This problem conveniently went away when i updated the Azure ServiceBus Nuget package to version 2.1.
To help debug this can you confirm on your local machine if you have Microsoft.ServiceBus.dll in the GAC? Also check if that version is different from what you have referenced in the project.
It seems like your project does not have the DLL, or a correct version of it. Build the applicaiton and look in the /bin folder. If you find the DLL (Microsoft.ServiceBus.dll), check the version and make sure it matches (Version=2.0.0.0). If you can't find it, it might be in your Global Assembly Cache.
If this doesn't help you, try:
1. Set copylocal = true in your reference properties so that the DLL is copied into your output directory.
2. Use nuget package manager to link to the Microsoft.Servicebus dll. It usually solves a lot of similar problems.

Resources