Failing to load ServiceBus Assembly when debugging - azure

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.

Related

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

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.

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

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

IIS skip assembly binding

I have a problem starting a Web Application of mine, which runs under IIS 8.
The 'yellow screen of death' states this:
Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' 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 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' 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 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' could not be loaded.
=== Pre-bind state information ===
LOG: User = IIS APPPOOL\XYZweb
LOG: DisplayName = RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b
(Fully-specified)
LOG: Appbase = file:///C:/Code/Application/XYZ 4-Web/ABC.XYZ.Web/
LOG: Initial PrivatePath = C:\Code\Application\XYZ 4-Web\ABC.XYZ.Web\bin
Calling assembly : ABC.RegularExpressions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=f59eabe05cc67589.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Application\XYZ 4-Web\ABC.XYZ.Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +371
System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +19
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +319
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +203
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1179
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +146
WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +114
WebActivator.ActivationManager.RunActivationMethods() +286
WebActivator.ActivationManager.RunPreStartMethods() +38
WebActivator.ActivationManager.Run() +56
[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12880923
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12880632
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +240
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12880068
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12721257
Now, I do have this RegexAssemblyBuilder.exe file in my solution and if I paste it into the bin folder and refresh the page everything works. It is also very likely that there is some issue about the calling assembly which looks for this file, and I have already informed my colleagues about that (I didn't develop it...). In the meantime, to make it work, and for future knowledge, I would like to know if there is the chance to tell IIS not to resolve this binding (which by the way I never use). I can't remove the calling .dll though.
Thank you
You could just set the Build Action to Content and then set Copy To Output Directory to Copy Always to have this assembly added to the bin directly at all tiimes. Otherwise, you could remove the reference to the executable from the project properties, or check to make sure that there is no mention of it in the web.config file. There is no method to prevent IIS from binding to an assembly when it is referenced inside a project. IIS builds up all the referenced assemblies when it does its initial compilation on the first request of the application.

Can't run my program on XP, because it says that can't load a dll(written by me), but on Windows 7 it runs

I've already seen some posts about my problem, but no solution...
My application needs to load a dll written by me, when I try to run it on Windows 7 it goes, but on XP it crashes.
So I tried to install VS2010 on XP and compiling there, it compiles correctly, but when i debug it throws System.IO.FileNotFoundException, because it "can't" load my dll (Could not load file or assembly 'Graphic.dll'), so it seems that can't find my dll, how can it be possible?
p.s: dll (managed class library) and exe are written in c++ and use .net framework 4
Fusion log 1: Assembly Binder Log Entry(09/04/2012 # 11.52.42)
The operation was successful. Bind result: hr = 0x0. The operation
completed successfully.
Assembly manager loaded from:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under
executable C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2010\Projects\MyProgram\Debug\MyProgram.exe A
detailed error log follows.
LOG: EXE explicit bind. File path:C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2010\Projects\MyProgram\Debug\MyProgram.exe.
Fusion log 2:
Assembly Binder Log Entry (09/04/2012 # 11.52.42) The operation was
successful. Bind result: hr = 0x0. The operation completed
successfully.
Assembly manager loaded from:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under
executable C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2010\Projects\MyProgram\Debug\MyProgram.exe A
detailed error log follows.
Pre-bind state information LOG: User = CASH-F32CDFF50A\Administrator
LOG: DisplayName = System.Windows.Forms, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/My
Documents/Visual Studio 2010/Projects/MyProgram/Debug/ LOG: Initial
PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL
LOG: AppName = MyProgram.exe Calling assembly : MyProgram,
Version=1.0.4482.18830, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context. LOG: No application
configuration file found. LOG: Using host configuration file: LOG:
Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Windows.Forms, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 LOG: Reusing an
assembly instance that was previously loaded
(C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll).

Resources