HttpClient failing - xamarin.ios

When I run my app on the emulator for iOS it works fine. When I run it on a device the first call to HttpClient fails. My class containing the HttpClient calls is in a PCL. It looks like an instance of this bug.
However, the documented workarounds of adding the following to your iOS project app.config does not work for me (the system.net.http addition);
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
EDIT:
With this in my app.config, the following method successfully retrieves the data from the server, but fails to read it. The bottom line containing ReadAsAsync(..) fails and throws an exception. The exception is 'null' and nothing is output to the terminal either. It works fine on the emulator, but not the device.
public async Task<List<ExternalLoginViewModel>> GetExternalLoginsAsync()
{
using (var client = GetNewHttpClient(false))
{
client.DefaultRequestHeaders.Remove("Authorization");
var response = await client.GetAsync("api/account/externalLogins?returnUrl=/&generateState=true");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsAsync<List<ExternalLoginViewModel>>();
}
}

Your assembly binding redirection is wrong. Your iOS project should have an app.config file with this content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The reason for the redirect is that the Microsoft.Net.HttpClient packages contains the System.Net.HttpClient namespace but that already exists on iOS and Android (with slightly different features even). At runtime it will resolve to the wrong assembly and not use the (Xamarin-)native iOS one.
You can find a demo project for iOS, Android and WP8 based on HttpClient in a PCL at my Github repo.

This was resolved by uninstalling the "Microsoft HTTP Client Libraries" nuget package from both the PCL and the iOS project. Then reinstalling on both. The iOS project has references now to 'System.Net.Http.Extensions' and to 'System.Net.Http.Primatives' but does not contain one to 'System.Net.Http'. The following binding redirect is used in the app.config file in the iOS project as well;
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />

Related

Owin packages version conflict

I have two projects in my solution, project1 and project2.
Project2 tends to self host with Owin.
I have enable CORS using Microsoft.Owin.Cors package.
Both project have Microsoft.OWIN 3.0.1 and Microsoft.AspNet.Cors
5.2.3.
Then, I copy my project2.exe to project1's debug folder and call
prorject2.exe from project1.
Then, then the exception box rises when trying to call project2.exe.
The message is that it requires System.Web.Cors version 5.0.0.0
assembly.
When I downgrade the Microsoft.AspNet.Cors to 5.0.0.0, it
again says it requires Microsoft.Owin version 2.0.2.
Why does this occur and how do I fix this version conflict? Both the projects is built under .Net Framewrok 4.5.2.
In order to resolve to conflict you must tell your code which version of OWIN to use. this can be done from your application's app.config.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

I am unable to see my tests in Test Explorer VS 2015 when creating CodedUI SpecFlow Tests

I am unable to see my tests in Test Explorer VS 2015 when creating CodedUI SpecFlow Tests.
I have a CodedUI project that I have added SpecFlow into and unlike using a SpecFlow Project I am unable to see the SpecFlow tests to run in the Test Explorer.
This is all on a Windows 7 VS2015 Ultimate edition env.
I have created a .runsettings file as recommended for 2013.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="MsTest" generatorProvider="Specflow.CodedUI.MsTestCodedUiGeneratorProvider, Specflow.CodedUI" runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTest2010RuntimeProvider, TechTalk.SpecFlow" />
<!-- <unitTestProvider name="SpecRun" />-->
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<plugins>
</plugins>
</specFlow>
<runtime>
<assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.VisualStudio.QualityTools.CodedUITestFramework" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.VisualStudio.TestTools.UITest.Common" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.VisualStudio.TestTools.UITest.Extension" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.VisualStudio.TestTools.UITesting" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.VisualStudio.QualityTools.CodedUITestFramework" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
<dependentassembly>
<assemblyidentity culture="neutral" name="Microsoft.Services.TestTools.UITesting.Html" publickeytoken="b03f5f7f11d50a3a">
<bindingredirect newversion="14.0.0.0" oldversion="10.0.0.0"></bindingredirect>
</assemblyidentity>
</dependentassembly>
</assemblybinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6"/>
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6"/>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
</DbProviderFactories>
</system.data>
</configuration>
</RunSettings>
I have selected the Test settings file to point at this file.
Still hitting a brick wall when I build my solution locally.
Now resolved this issue
If you have your project setup to save into your network folder not a local folder then Test Explorer does not trust/recognize the DLL the project creates on build and therefore will not display the tests.
If you have the project either saved onto your local drive (C or D) or alternatively get the network drive to be recognized as trusted.

Role has encountered an error and has stopped

I am facing problem very similar to problem what we have in this question.
We have a standard MVC5 application that we have deployed on Windows Azure using webrole.
After deploying I can see below error message on visual studio 'Microsoft Azure Activity Log' window
Your role instances have recycled a number of times during an update or upgrade operation. This indicates that the new version of your service or the configuration settings you provided when configuring the service prevent the role instances from running. Verify your code does not throw unhandled exceptions and that your configuration settings are correct and then start another update or upgrade operation.
I can see below error message on management console.
Restarting (Role has encountered an error and has stopped. Sites were deployed. [2014-10-22T04:46:57Z])
I found below error message in event viewer. ( inside VM )
The description for Event ID 1007 from source Windows Azure Runtime 2.4.0.0 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
2232
WaIISHost
Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.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)
File name: 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
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].
---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
the message resource is present but the message is not found in the string/message table
I don't know why its referring to version 4.0.0.0
My section of web.config file looks like this.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Your web.config controls w3wp.exe, but your callstack indicates that you are crashing in WaIISHost.exe. You have a couple options:
Why are you referencing System.Web.Mvc in your role entry point DLL (typically WebRole.cs)? If you can refactor this part of your code then you don't have to worry about loading this DLL and all of it's dependencies in your WaIISHost process.
Create an app.config with the same binding redirect you have in your web.config.
I got the solution for this problem. I found location of WaIISHost.exe and modify existing WaIISHost.exe.config file by adding binding redirect statements to it.
You can find this file under 'E:\base\x64'
I had this problem with version 5.1 and I had to set the MVC dll copytolocal=true. I believe it is related to the previous MVC security update. This is Microsoft's brute force away of insisting you update MVC.

Async controller method displays type name of Task<ActionResult>

I am playing around with ASP.NET MVC5 and RavenDB. I wanted to use Raven's asynchronous API but for the life of me can't get it to work.
My controller (the actual query result is faked since there is no data in the DB)
public class BooksController : Controller
{
public async Task<ActionResult> IndexAsync()
{
var books = this.documentSession.Query<Book>();
Book book = await books.FirstOrDefaultAsync() ??
new Book { Title = "Programming WCF service", ASIN = "B0043D2DUK" };
return this.View(book);
}
}
And the view IndexAsync.cshtml
#using Hydra.FubuConventions
#model Hydra.Models.Book
#{
ViewBag.Title = "Books Asynchronous";
}
<h2>Books Asynchronous</h2>
#Html.FormBlock(x => x.Title)
#Html.FormBlock(x => x.ASIN)
The Web.config
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<customErrors mode="On" defaultRedirect="Error.html"/>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
It works perfectly fine when I use a synchronous controller method to feed it with a model. But with the asynchronous method it only displays
System.Threading.Tasks.Task1[System.Web.Mvc.ActionResult]`
I found plenty of posts here on stackoverflow that indicate that an older version of MVC might be the problem. But I checked the version of the MVC dlls (System.Web.Helpers v3.0.11001.0, System.Web.Mvc v5.0.11001.0 and System.Web.WebPages v3.0.11001.0) in my output folder which seem to be correct.
Any ideas what I am missing?
UPDATE
I compared the list of loaded assemblies. Other than the obvious differences by assemblies loaded in only one of the projects they were a match. The web.config is identical. I replaced the call to RavenDB with the same test stub that I used in the new project. Still get the type name rather than the view.
If you use a custom ControllerActionInvoker, you'll have to inherit it from AsyncControllerActionInvoker.
You must target .NET 4.5 and set httpRuntime.targetFramework to 4.5 in your web.config.
Your web.config lacks the assembly redirection directives found on a new MVC project. I suspect older MVC assemblies are installed in the GAC and are picked up by your app.
In any case, the behavior is a typical version mismatch. You need to find why the older assemblies are loaded by comparing the differences between your project and a new, clean MVC 5 project.
On a new MVC 5.2 project, the <runtime> section in web config contains these assembly redirections:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
You should copy the redirections from the clean project to your old project and see whether this solves the problem

he type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception

After moving my Azure web app to SDK 2.1 I have started getting the
type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.
error message. The same is working fine in the local environment but gives above error on Azure.
My web.config already has following entries:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.StorageClient"
publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.7.0.0" newVersion="1.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime"
publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.8.0.0" newVersion="1.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Diagnostics"
publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
and
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
still it's not working in live Azure. Can someone please help me out?
It is possible that you may be running different Windows Azure DLLs than the ones installed (by default) on live Azure instance roles. Right click the Microsoft.WindowsAzure.[any] references in your project and check the version number in the Properties window and try to match them with the version numbers in your config files.

Resources