Azure Functions : HttpRequestMessage does not contain a definition for 'CreateResponse' - c#

I built a c# Azure functions app triggerred by an Http Request. The purpose of this app is to use digital twin to change the desired status of my device. In order to do that, I have imported the following dependencies (within the project.son file):
"Microsoft.Azure.Devices": "1.17.2",
"Microsoft.Azure.Devices.Client": "1.19.0",
"Microsoft.Azure.Devices.Shared": "1.15.2",
"Newtonsoft.Json": "12.0.1"
Here is my error, when I want to return a HttpResponseMessage
req.CreateResponse<string>(HttpStatusCode.BadRequest, "Please pass a status on the query string or in the request body");
I get the following error :
[run.csx] 'HttpRequestMessage' does not contain a definition for 'CreateResponse' and the best extension method overload 'HttpRequestMessageExtensions.CreateResponse<string>(HttpRequestMessage, HttpStatusCode, string)' requires a receiver of type 'HttpRequestMessage'
I suspect dependencies to cause this error but I haven't found any solution on internet.
Do you have an idea how to solve this ?
Thanks

Solution:
Go to kudu(https://<functionapp>.scm.azurewebsites.net/DebugConsole) and navigate to D:\home\data\Functions\packages\nuget, delete system.net.http package then restart the function app.
Explanation:
HttpRequestMessage locates at assembly System.Net.Http.dll. I found that Function host references the assembly from GAC(Global Assembly Cache). On Azure, file path is D:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll. The reference cannot be redirected to the one we install using nuget(packages you installed reference System.Net.Http.dll internally), or we'll get error.

Related

WCF Async Web Services issues

I'm having several issues with my WCF client in that the client Reference.cs is empty and the only error I get on the build is the useless generic message:
Severity Code Description Project File Line Suppression State
Warning Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='IBrokerWcf'] MyWeb.Setup C:\Users\me\Projects\MyWeb 3.x\MyWeb v3.x\MyWeb.Setup\Service References\BrokerWcfSvc\Reference.svcmap 1
When I load the Service in the WCF Test Client, all of the advertised async methods error out (see image) with "This Operation is not supported in the WCF Test Client because it uses type System.Threading.Tasks.Task'1"
All of this previously worked fine. Not sure what changed to send it all sideways.
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: The located assembly's manifest definition does not match the
assembly reference.
As the error says, the manifest definition of the locating assembly does not match the assembly reference.
You need to check the components. Did you click "Reuse types in referenced assemblies" when adding a service reference.
This Operation is not supported in the WCF Test Client because it uses
type System.Threading.Tasks.Task'1"
The "error" you are seeing is just a limitation of the test tool that comes with visual studio, both functions call the same server side function so there is no compelling force to make Microsoft add support. There is no actual error. If you really want to test the async version you will need to write your own test client that calls the function.
Error : not supported in WCF Test client because it uses type System.Threading.Tasks

The mysterious "Couldn't not load file or assembly 'System.ServiceModel, Version=4.0.0.0..." error

Scenario: I have a WCF endpoint (endpoint Manufacturing) that connects another WCF endpoint (endpoint DataAPIClient) as ConnectedService. The constructor of an entity in A instantiate the "client" (see below). On top of all these, I have a xUnit test project testing A.
// Manufacturing constructor
public Manufacturing() {
client = new DataAPIClient();
}
// Instantiating in the xUnit project
Manufacturing endpoint = new Manufacturing();
Problem: Something changed (and I couldn't figure out what) that when the test project tries to instantiate Manufacturing. I got this error:
Message: System.IO.FileNotFoundException : Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
I have verified the System.ServiceModel.dll in both endpoints. DataAPIClient has 4.0.30319 and manufacturing has 4.0.0.0.
P.S. I did change the name of the Manufacturing project...not sure if that caused that, but I thought it might be worth of mentioning.
Any help is greatly appreciated...I've been googling and found nothing.
per howcheng's suggestion, I noticed that since I was using xUnit Test Project (.NET Core), I couldn't (or maybe I just didn't know how) add any reference to System.ServiceModel.dll. So I created a Unit Test Project (.NET Framework) and added the xUnit Nugets and System.ServiceModel.dll assembly. The error went away.

tweetinvi working on local host but throwing dll error on azure server

The error below occurs when attempting to make an api request using tweetinvi running on an azure web role.
Could not load file or assembly 'System.Threading.Tasks,
Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
I tried installing the nuget package for this dll, but then I get a compilation error (same type being declared in two places,) because apparently, system.threading.tasks in bundled inside of mscorlib.dll
.NET version: 4.5
tweetinvi version : v4.0.30319 strong name
I assume that you mentioned tweetinvi version is the Runtime Version. I do a demo using TweetinviAPI. It works correctly on my side. If it is possible, please have a try to redeploy it again or create new cloudservie to test it again..
The following is my detail steps:
1.Create cloudservive project and with WebRole.
2.Reference the tweetinvi with Nuget
3.Create Tweetinvi application (https://apps.twitter.com/) and get the Consumer Key,Consumer Secret, Access Token, Access Token Secret
4.Add the following code in the HomeController About() to test it.
Auth.SetUserCredentials(string consumerKey, string consumerSecret, string userAccessToken, string userAccessSecret);
// Publish the Tweet "Hello Tweetinvi" on your Timeline
Tweet.PublishTweet("Hello Tweetinvi! ");
5.Publish the cloudservice to Azure and visit(http://xxxxx.cloudapp.net/Home/About) get the test result.
6.Check from twitter, it works correctly

Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral

The context of this issue is .net core 1.1 and electron-edge:
I created a super simple C# library in .Net Core 1.1 with .Net Standard 1.6. I finished dotnet restore, dotnet build and dotnet release etc. .... per the documentation successfully. Things went on well and I moved all DLLs, json files, etc. from the publish folder to a folder called "dll" within the folder where node runs. So, it looks like this: C:\electron-quick-start\dll
var clrMethod = edge.func({
assemblyFile: 'dll\\MyLibrary.dll',
typeName: 'MyLibrary.Startup',
methodName: 'Invoke'
});
clrMethod('This text comes from JavaScript!', function (error, result) {
if (error) throw error;
console.log(result);
});
When I run the js file, I receive the error message mentioned in the subject line. Then I set the following environment variables:
EDGE_USE_CORECLR=1
EDGE_APP_ROOT = C:\electron-quick-start\dll
But I received this error message / exception:
TypeError: edge.initializeClrFunc is not a function
Even I tried to put all contents of "dll" folder side by side where node is running and that resulted into no success. Also, I set app root to the exact publish folder generated by dotnet release and that was not conclusive either.
What is missing in this exercise or may have been done wrong?!
As a side note: I am using the recent version of electron-edge.

ASP.NET Attempt by method ... to access field 'System.Data.SqlClient.xxx._connection' failed

I'm using a package from NuGet which works on localhost, worked on a production server but after a recent move to a different production server, I get the following error:
Attempt by method 'EntityFramework.BulkInsert.Extensions.TypeExtensions.GetPrivateFieldValue(System.Object, System.String)' to access field 'System.Data.SqlClient.SqlConnection._connectionString' failed.
The package is: https://efbulkinsert.codeplex.com/ I don't think it's package specific because using an alternative package for bulk inserts I get a similar error:
Attempt by method 'Z.Utility.SqlBulkOperation.SetCommonSetting()' to access field 'System.Data.SqlClient.SqlBulkCopy._connection' failed.
The common thing here is System.Data.SqlClient.xxx._connection failed
Are there any IIS setting I need to look at? I'm stumped.
I had to change the .NET Trust Levels from Medium to Full in IIS.

Categories

Resources