0

Problem description: I created an MVC API which will be called with a WPF application or a xamarin.forms app. The call itself results in no error if I don't call the function with an object. I had a running version a bit longer ago and it also was a different solution. Now I have instead of 2 .NET Framework shared projects 2 .NET Standard projects. This project doesn't contain any server logic. They contain only the database and transfer objects. To transmit objects I use Newtonsoft.Json

PostAsJsonAsync(path, object)

Now there are 2 type of problems:

  1. First if I leave everything as it is, the methods with no parameters will be called without problems. But if I try to call a method with an object it will resolve the following error (this is the error message which the server returns, I'm 99% sure that the client does have no problems, because if I try the same method on the old solution it runs *1):

{"Message":"Fehler","ExceptionMessage":"Methode nicht gefunden: \"Void System.Web.Http.HttpResponseException..ctor(System.Net.Http.HttpResponseMessage)\".","ExceptionType":"System.MissingMethodException","StackTrace":" bei RohrAG.Inspect.Server.Api.Controllers.VerificationController.Login(LoginDto loginDto)\r\n bei lambda_method(Closure , Object , Object[] )\r\n
bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n bei System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n bei System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---\r\n bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n bei System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

  1. I can resolve this error by double click the server warning, which is the following:

Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: MySolution.Api *2

After it added a lot of dependentAssemblies it is working halfway. I can send objects to the server without receiving an error message but the object that the server receives is null. (I'm still sure that the client is functionally! I tried to call a method on a different solution with an object and where the server is receiving the object without problems.)

*1 I tried to copy the old project to the new solution. Didn't worked anymore. I also created a new project with the same settings to prevent any move errors, doesn't work either

*2 Somehow stackoverflow isn't showing the full message in the preview (It tells me it does look like spam so^^). If it stays like this, the warning just tells me that there are somehow problems with dependentAssembly. My web.config contains this before the fix: assemblyBinding before fix

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
  • Looks like method needs a json string like : var response = client.PostAsync("api/AgentCollection", new StringContent( new JavaScriptSerializer().Serialize(user), Encoding.UTF8, "application/json")).Result; See : https://stackoverflow.com/questions/19158378/httpclient-not-supporting-postasjsonasync-method-c-sharp – jdweng Feb 12 '18 at 22:36
  • @jdweng thanks but doesn't work in this case. I tried to move my files from my .NET Standard to my .NET Framework projects which "resolves" the error. I now have 2 solutions, but I can't and don't want to leave it this way. It seems like an issue inside .NET Standard to me. (This isn't sure but from my current perspective the most reasonable). I also need to mention that my .NET Standard project contains the NUGET _System.ComponentModel.Annotations_. Note: To me it's now 100% sure that the server is the problem. Not the client. (Based on testing and the issue "resolve") –  Feb 13 '18 at 08:12
  • Are you sending? Use a sniffer like wireshark or fiddler to verify the send data to make sure you are actually sending. Is the exception at the client or server. If it is at the server why would a server issue cause an exception at client? – jdweng Feb 13 '18 at 09:03
  • @jdweng 1.No but yes.I don't use something like wireshark at the moment but I tried to use the same client as it is (no changes, same solution) to call the server from a different solution with the same settings with the only difference that the server library project is instead of .NET Standard, .NET Framework. The error was thrown by the server and only catched by the client. I'm sorry if I didn't made this sure enough, my fault. And at my current state the problem is somehow caused with the class library which is based on .NET Standard instead of .NET Framework. I'm currently not sure why. –  Feb 13 '18 at 09:35
  • Again. Using sniffer which will give the headers and data you can compare the working client with the failed client to find out the exact issue. It looks like the server is sending an error response or no response and you are getting a timeout. The server will normally send a response 200 Done if it accepts the client request. The status can be seen with the sniffer. – jdweng Feb 13 '18 at 10:19

0 Answers0