Azure Functions dll version mismatch - azure

We have an Azure function which references an external assembly via a private Nuget feed.
The problem we're having is that we have two different versions of Microsoft.Azure.WebJobs.dll - one which is a dependency of our nuget package and another which I'm assuming is being provided by the runtime.
error CS1503: Argument 2: cannot convert from 'Microsoft.Azure.WebJobs.ICollector<Microsoft.WindowsAzure.Storage.Table.ITableEntity> [D:\Program Files (x86)\SiteExtensions\Functions\1.0.10635\bin\Microsoft.Azure.WebJobs.dll]' to 'Microsoft.Azure.WebJobs.ICollector<Microsoft.WindowsAzure.Storage.Table.ITableEntity>
I found this question which says that binding redirects are not supported:
Azure Functions binding redirect
We could try to remove our dependency on that library, or we could match the version used by Azure Functions, but I think we're going to have the same problem with using Microsoft.WindowsAzure.Storage anyway.
Please advise!

You are correct that binding redirects are not supported. The runtime has its own dependencies on the WebJobs SDK and Storage libraries so objects passed into your functions will be from those versions. I recommend removing your dependencies on other versions and snapping to ours. Note that for these libraries, you don't have to add your own package reference, you can reference ours in your function code via:
#r "WindowsAzure.Storage"
You don't need to add explicit #r references for WebJobs SDK types (e.g. ICollector<T>) - the runtime adds that assembly implicitly. Of course this only applies for function code we're compiling for you, not code coming from your external packages.
In the future we might improve things in this area, but for now you'll be swimming up stream if you try to use conflicting versions.

Related

How to fix deprecated nuget-package NLog.Config

Just noticed that in my list of Nuget packages, that "NLog.Config" is marked as deprecated:
Is it safe to simply delete the package?
This particular application is for Google Calendar API usage.
I should have looked more closely at my code. I removed the package and now my tool won't compile. I have code like:
Imports NLog
Private m_logger As NLog.Logger = LogManager.GetCurrentClassLogger()
And 10 instances of calls like:
m_logger.Error(ex, "RESULT_FAILED_OAUTH")
How to resolve now that NLog is deprecated?
NLog.config-nuget-package is safe to remove, and one is encouraged to remove it. It became obsolete when Microsoft introduced <packagereference>-syntax.
Now the NLog.config-nuget-package actually causes issues because it can reset the NLog.config-file on application-publish (Same story can also seen on the nuget-package-page)
Just replace it with NLog-nuget-package, if you don't have it installed already.

What is the difference between the Microsoft.Azure.Storage and WindowsAzure.Storage Nuget packages?

I've always found this very confusing:
There is a WindowsAzure.Storage NuGet package authored by Microsoft which allows you to work with, for example, blob storage (creating blobs, etc.).
There are also Microsoft.Azure.Storage.* packages which accomplish the same thing, also authored by Microsoft.
If your project happens to have dependencies on both, you can have naming conflicts e.g. (The type 'CloudStorageAccount' exists in both 'Microsoft.Azure.Storage.Common, ... and 'Microsoft.WindowsAzure.Storage, ...).
Here are links to the two alternatives:
https://learn.microsoft.com/en-us/dotnet/api/overview/azure/storage?view=azure-dotnet
https://github.com/Azure/azure-storage-net/blob/master/README.md
What is the difference and when would I be motivated to use one over the other?
WindowsAzure.Storage(latest is v9.3.2) is the legacy Storage SDK we always use and Microsoft.Azure.Storage.*(latest v9.4.0) is its new release, nuget available about one year.
Check the changelog of Storage .NET SDK. List part of those important differences/changes.
Microsoft.Azure.Storage splits libraries to three parts, Blob, Queue and File, which means we can install separate package instead of the full edition.
Microsoft.Azure.Storage doesn't support Table API, it is transferred to Microsoft.Azure.Cosmos.Table.
Microsoft.Azure.Storage added NetStandard2.0 target support since 9.4.0-preview, which supports synchronous methods wrapped over the asynchronous APIs. WindowsAzure.Storage on NetStandard only has asynchronous APIs.
Microsoft.Azure.Storage v9.4 package moves back to use Microsoft.WindowsAzure.Storage namespace temporarily to ease the transition for existing libraries.
Just make choices based on our requirement.
There are now three levels:
WindowsAzure.Storage - up to v9.3.3 - don't use this anymore.
Microsoft.Azure.Storage - v9.4.0 to v11.1.7 - older
Azure.Storage - v12.x - use this library.
All the Azure libraries are being consolidated into the Azure namespace, so the newer libraries all start with Azure (not Microsoft.Azure or WindowsAzure) and you should use those when available.

Azure Functions V1 linking wrong version of the RestSharp.dll

Guys I know that the azure functions cli has a dependency with RestSharp.dll and I think that is conflicting with one of my Azure Functions.
I am getting a runtime type exception
System.TypeLoadException: 'Could not load type 'RestSharp.IAuthenticator' from assembly 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null'.'
Now my azure function is dependent on RestSharp nuget Version 104.4.0.0. There is no reference in my project to Version 105.2.3.0. Here is the interesting thing. In my despair I searched my entire computer for the culprit dll version 105.2.3.0 and I found it at AppData\local\Azure.Functions.Cli\1.0.12
Is that it ? Is the Azure functions runtime trying to link with its RestSharp.dll version instead of the dll version of my project ?
Runtime should technically load version 104.4.0.0. However it is still loading the version referred by the runtime (105.2.3.0). I was able to verify this behavior. Have filed a bug for this https://github.com/Azure/azure-functions-host/issues/2832.
In the meantime is it possible to do one of the following:
Update the code to use 105.2.3.0, I see RestSharp.IAuthenticator type is present. It is under a different namespace. There should be another method exposing the same functionality
If the function app is not being used in prod. You could use the beta runtime. You should not encounter this issue in beta runtime (v2.x)

References within an azure functions project not working

So I have some Azure Functions I need to publish, which I want to do via a functions project. However, those functions rely on references to class libraries within my solution, and the references do not work within a functions project, is there a way around this?
Edit: After adding the references to the other projects, when "using" the namespaces in which the classes are kept, the compiler throws an error "cannot resolve symbol", it is as if the reference does not exist. The functions project will not build because it cannot find the namespace in which the classes exist
Verify that each project targets the same version of .NET framework. I had the same problem until I noticed that the referenced project targeted 4.7.1, but my Azure function project targeted 4.6.1. Changing the referenced project to match the Azure function project resolved the issue.
There are a couple more steps to consume assemblies if they're not exposed by default in Azure Functions. If it's a custom assembly you have to make sure it's included in the bin folder. Then you have to make sure you're using the #r directive. Are you doing both of those things? Include your code header and settings if so.
This page has the list of assemblies that are visible to Azure Functions, some still requiring the #r directive:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies
The following assemblies are automatically added by the Azure Functions hosting environment:
mscorlib
System
System.Core
System.Xml
System.Net.Http
Microsoft.Azure.WebJobs
Microsoft.Azure.WebJobs.Host
Microsoft.Azure.WebJobs.Extensions
System.Web.Http
System.Net.Http.Formatting
The following assemblies may be referenced by simple-name (for
example, #r "AssemblyName"): Newtonsoft.Json
Microsoft.WindowsAzure.Storage Microsoft.ServiceBus
Microsoft.AspNet.WebHooks.Receivers Microsoft.AspNet.WebHooks.Common
Microsoft.Azure.NotificationHubs

Using WindowsAzure.Storage in ASP.NET Core

I'm using VS 2017 RC. I've been told to use it to get the proper experience with .net core going forward, so that is where I am at.
I am trying to add the nuget package WindowsAzure.Storage into my ASP.NET Core application. I keep getting a message stating that one of the dependencies is not compatible.
From reading up in some various forums, the problem appears to be the OData dependency. Additional reading has shown that if this were running under VS 2015, I could use an imports statement in the project.json file to get this to work.
Question: what is the equivalent statement that I can add an imports statement into the vs2017rc proj file?
what is the equivalent statement that I can add an imports statement into the vs2017rc proj file?
PackageTargetFallback is a new design for Imports and is used in csproj, if you’d like to know detailed information, please read this documentation.

Resources