I am creating a UI test for my Xamarin.Forms app. When I try to start the first test for iOS project, I get a System.Xml.XmlException (detailed below). This basic test should be working, right?
Update: If I uninstall the app from the simulator, the test runs for the first time. After that I keep getting the exception for all following runs.
I am using Xamarin Studio (6.1.3 build 19) and
Xamarin.UITest package (2.0.5)
namespace UITest
{
[TestFixture (Platform.Android)]
[TestFixture (Platform.iOS)]
public class Tests
{
IApp app;
Platform platform;
public Tests (Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest ()
{
app = AppInitializer.StartApp (platform);
}
[Test]
public void AppLaunches ()
{
try {
app.WaitForElement ("Waiting for fake element", "Timeout", new TimeSpan (0, 0, 20));
} catch (TimeoutException ex) {
int i = 5;
}
app.Screenshot ("Welcome screen.");
app.Tap ("TestButton");
app.Screenshot ("New test screen.");
}
}
public class AppInitializer
{
public static IApp StartApp (Platform platform)
{
if (platform == Platform.Android) {
return ConfigureApp
.Android
.StartApp ();
}
return ConfigureApp
.iOS
.Debug ()
.EnableLocalScreenshots ()
.StartApp ();
}
}
}
Exception details:
SetUp : System.Xml.XmlException : '', hexadecimal value 0x01, is an invalid character. Line 11, position 11.
Stack trace:
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchAppLocal (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, System.Boolean clearAppData) [0x0020a] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchApp (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, Xamarin.UITest.TestCloud.TestCloudiOSAppConfiguration testCloudAppConfiguration, Xamarin.UITest.Shared.Http.HttpClient testCloudWsClient, Xamarin.UITest.Shared.Http.HttpClient xtcServicesClient, System.Boolean testCloudUseDeviceAgent) [0x0007a] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.iOS.iOSApp..ctor (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration) [0x00302] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.Configuration.iOSAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <e747267e258a4a668973c7ca7e9014a8>:0
at UITest.AppInitializer.StartApp (Xamarin.UITest.Platform platform) [0x0001f] in /Users/samg/projects/myapp-mobile/myapp-mobile-2/UITest/AppInitializer.cs:38
at UITest.Tests.BeforeEachTest () [0x00008] in /Users/samg/projects/myapp-mobile/myapp-mobile-2/UITest/Tests.cs:26
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
I know this is an old question, however it might help others. I experienced the same problem described above and solved it by resetting the iOS simulator.
One way to accomplish this is to take the following steps:
Make sure the iPhone/iPad simulator is running;
Go to the top-menu and select "iOS Simulator" -> "Reset Content and Settings..."
Related
I'm having the weirdest issue and I have no idea why.
When deploying our .net core 2.2 api to our local IIS server I get the following error message:
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
After checking the event log I this is the error that I find:
Application: dotnet.exe
CoreCLR Version: 4.6.27207.3
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: No service for type 'Digitise.Infrastructure.Services.DatabaseMigrator' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Digitise.ApiBase.BaseProgram.Initialise(String[] args, IWebHost host) in C:\Projects\Digitise.AspNetCore\Digitise.ApiBase\BaseProgram.cs:line 17
at Digitise.Api.Program.Main(String[] args) in C:\Projects\Digitise.AspNetCore\Digitise.Api\Program.cs:line 27
It seems like the DI is not working correctly! The weird thing is if I run the api.exe or dotnet api.dll the API works perfectly :/
Anyone have any ideas? :)
Program.cs
public class Program
{
public static object _lock = new object();
public static bool _init = false;
public static void Main(string[] args)
{
var host = CreateWebHostBuilder(args);
Initialise(args, host);
}
public static IWebHost CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
//.UseIISIntegration()
.UseIIS()
.UseNLog()
.UseShutdownTimeout(TimeSpan.FromSeconds(10))
.Build();
public static void Initialise(string[] args, IWebHost host)
{
var logger = NLogBuilder.ConfigureNLog(Path.Combine(Directory.GetCurrentDirectory(), "NLog.config")).GetCurrentClassLogger();
try
{
logger.Debug("App init");
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
if (!_init)
{
lock (_lock)
{
if (!_init)
{
lock (_lock)
{
services.GetRequiredService<DatabaseMigrator>().Migrate();
}
}
}
}
}
catch (Exception ex)
{
logger.Error(ex, "An error occurred while starting up the app.");
throw;
}
}
host.Run();
}
catch (Exception e)
{
logger.Error(e, "Stopped app due to exception");
throw;
}
}
}
DatabaseMigrator.cs
public class DatabaseMigrator
{
private readonly TenantDbContext _tenantDbContext;
private readonly IOptions<DatabaseConfiguration> _databaseConfig;
private readonly ILogger<DatabaseMigrator> _logger;
private readonly AdminTenantDbInitialiser _adminTenantDbInitialiser;
public DatabaseMigrator(TenantDbContext tenantDbContext, IOptions<DatabaseConfiguration> databaseConfig, ILogger<DatabaseMigrator> logger, AdminTenantDbInitialiser adminTenantDbInitialiser)
{
_tenantDbContext = tenantDbContext;
_databaseConfig = databaseConfig;
_logger = logger;
_adminTenantDbInitialiser = adminTenantDbInitialiser;
}
public void Migrate()
{
//migration logic
}
}
I've just gone through a lot of pain fixing a similar problem. Pretty sure the problem is you using Directory.GetCurrentDirectory(), this does odd things when running with in-process hosting as in IIS. I replaced it with Assembly.GetExecutingAssembly().Location and all worked fine.
Clue came from Dotnet Core Multiple Startup Classes with In-Process Hosting
In my case the issue started to show up after I updated some Nuget packages. Installing the latest .NET Core SDK has helped.
I have created a .Net Core 2 API using OData 4.0 (part of AspNetCore.OData 7.1.0).
Everything, except the "$search", seems to work.
The documentation says it should work.
The following requests I tested didn't work:
http://host/service/Products?$search=banana
http://host/service/Products?$search="banana"
http://host/service/$all?$search="banana"
error message:
{"message":"The query parameter 'Specified argument was out of the range of valid values.\r\nParameter name: $search' is not supported.","exceptionMessage":"Specified argument was out of the range of valid values.\r\nParameter name: $search","exceptionType":"System.ArgumentOutOfRangeException","stackTrace":" at Microsoft.AspNet.OData.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.<>c__DisplayClass1_0.<OnActionExecuted>b__3(ODataQueryContext queryContext)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)"}
The following requests I tested worked:
http://host/service/$metadata/
http://host/service/Products?$filter=contains(name, "banana")
My code:
Configure app (defined in Startup.cs):
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// Cors
app.UseCors(builder => builder
.WithOrigins("*")
.AllowAnyHeader()
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowCredentials()
);
//app.UseHttpsRedirection();
app.UseMvc(routeBuilder =>
{
routeBuilder.MapODataServiceRoute("odata", $"service/", GetEdmModel());
routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
routeBuilder.EnableDependencyInjection();
});
}
EdmModel (defined in Startup.cs):
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Product");
builder.EntitySet<Producer>("Producer");
builder.EntitySet<Consumer>("Consumer");
return builder.GetEdmModel();
}
.Net Core 2.2 Api "Get" (ProductsController.cs):
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<Product>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[EnableQuery]
public async Task<ActionResult<Product>> Get()
{
var dbResponse = _context.Products.AsQueryable();
return this.OK(dbresponse);
}
I am trying to create an owin web app using token authentication, my startup does not have any special setup like the example in
https://github.com/NancyFx/Nancy/wiki/Token-Authentication
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
}
}
mine is simply
public void Configuration(IAppBuilder app)
{
app.UseNancy();
}
I have the module defined like
public HomeModule(ITokenizer tokenizer)
{
Post["/login"] = _ =>
{
DefaultUserIdentityResolver resolver = new DefaultUserIdentityResolver();
//var userName = (string)this.Request.Form.Username;
//var password = (string)this.Request.Form.Password;
var claims = new List<string> { "admin", "poweruser" };
var userIdentity = resolver.GetUser("ross", claims, Context);
if (userIdentity == null)
{
return HttpStatusCode.Unauthorized;
}
var token = tokenizer.Tokenize(userIdentity, Context);
return new
{
Token = token,
};
};
}
Not much just yet I know but when when I get to tokenize I get an exception of the type Nancy.ErrorHandling.RouteExecutionEarlyExitException which really doesnt have anything in the message or stack trace to indicate the issue.
I am currently hosting over http in casini on .NET 4.5.1
Any pointers would be appreciated
Update:
Message is:
Exception of type 'Nancy.ErrorHandling.RouteExecutionEarlyExitException' was thrown.
Stack trace is:
at Nancy.Authentication.Token.Tokenizer.Tokenize(IUserIdentity userIdentity, NancyContext context)
at Samaritan.Hosting.HttpServices.HomeModule.<>c__DisplayClass11.<.ctor>b__7(Object _) in c:\src\DukeSoftware\Samaritan\Main\Samaritan.Hosting.HttpServices\HomeModule.cs:line 39
at CallSite.Target(Closure , CallSite , Func`2 , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)
I tried setting up the startup.cs like this
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseNancy();
}
}
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
TokenAuthentication.Enable(pipelines, new TokenAuthenticationConfiguration(container.Resolve<ITokenizer>()));
}
}
but I got the following exception
{"Located multiple bootstrappers:\r\n - Samaritan.Hosting.HttpServices.BootStarapper\r\n - Samaritan.Hosting.HttpServices.Bootstrapper\r\n\r\nEither remove unused bootstrapper types or specify which type to use."}
So I removed the bootsrapper and just left Startup. An instantiated tokenizer seems to be passed into the module when you declare the constructor public HomeModule(ITokenizer tokenizer)
So I didnt think the creation of the tokenizer was a problem
did you find fix?
I'm encountering the same exception. It's because I have 2 EXE files in the same directory having child of 'DefaultNancyBootstrapper' class.
I gotta use old Nancy v1.0. so it seems there's no other way but to use 'DefaultNancyBootstrapper' in only one place.
I have a RadioGroup with very many RadioElements as a Sub-DialogViewController:
Root.Add(
new Section() {
new RootElement ("Demo", new RadioGroup ("demogroup", 0)) {
new Section () {
from demoItem in bigItemList
select (Element) new RadioElement (demoItem)
}
}
}
);
I want to enable Search for this nested DVC to make picking the right RadioElement simpler. Therefor I implemented a custom RootElement which combines passing a Group and creating a DVC with EnableSearch and used it instead of the one above:
using System.Collections.Generic;
namespace MonoTouch.Dialog
{
public class SearchableRootElement : RootElement
{
public SearchableRootElement(string caption, Group group) : base(caption, group)
{
this.createOnSelected = x => {
return new DialogViewController(x) { EnableSearch = true };
};
}
}
}
Unfortunately when typing into the Searchbar of the sub DVC I get the following crash:
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at MonoTouch.Dialog.RadioElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1066
at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:341
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at Demo.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rodjatrappe/Projects/Claas/Dev/Apps/Demo.iOS/Main.cs:16
2013-06-22 14:15:02.296 DemoiOS[547:21b03] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
at MonoTouch.Dialog.RadioElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1066
at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:341
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at Demo.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rodjatrappe/Projects/Claas/Dev/Apps/Demo.iOS/Main.cs:16
Why is it crashing and how to archive the feature I described above?
I cannot give you a direct answer but you may (assuming your source is not out of sync with this one) want to have a look at Line 1066 -
https://github.com/migueldeicaza/MonoTouch.Dialog/blob/master/MonoTouch.Dialog/Elements.cs
if (!(root.group is RadioGroup))
Is root null? Consider downloading the MTD source code and debugging it, check how you are creating your DVC.
You could also replace your LINQ with a couple of hard coded sections, ensure that is not your issue.
Hope this helps
The bug report here includes a workaround for the root cause of the issue you're experiencing, but also talks about how filtering will then cause a usability issue of marking the nth element as selected even after a filter has been applied.
https://github.com/migueldeicaza/MonoTouch.Dialog/issues/203
If you don't want to update the core MTD code, you could use that same technique by putting it in your own UIBarSearchDelegate. Unfortunately, the default SearchDelegate class is internal, so you'll need to add all of the code in your delegate. I was able to do this and get it working without changing the MTD source:
public override void LoadView()
{
base.LoadView();
((UISearchBar)TableView.TableHeaderView).Delegate = new MySearchBarDelegate(this);
}
And then you use this instead of the base method:
public override void TextChanged (UISearchBar searchBar, string searchText)
{
container.PerformFilter (searchText ?? "");
foreach (var s in container.Root)
s.Parent = container.Root;
}
# first I thought it wasn't firing, but saw this
So I waited and now I get Unhandled Exception: MonoTouch.Foundation.You_Should_Not_Call_base_In_This_Method: Exception of type 'MonoTouch.Foundation.You_Should_Not_Call_base_In_This_Method' was thrown. in the failed handler.
I have defined a CLLocationManager, here is FinishedLaunching & CLLocationManagerDelegate
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// window.AddSubview (navigationController.View);
_locationManager = new CLLocationManager();
_locationManager.Delegate = new LocationManagerDelegate(this);
_locationManager.StartUpdatingLocation();
window.MakeKeyAndVisible ();
return true;
}
private class LocationManagerDelegate : CLLocationManagerDelegate
{
private AppDelegate _appd;
public LocationManagerDelegate(AppDelegate appd)
{
_appd = appd;
Console.WriteLine("Delegate created");
}
public override void UpdatedLocation(CLLocationManager manager
, CLLocation newLocation, CLLocation oldLocation)
{
Console.WriteLine("Lat: " + newLocation.Coordinate.Latitude.ToString());
}
public override void Failed (CLLocationManager manager, NSError error)
{
//_appd.labelInfo.Text = "Failed to find location";
Console.WriteLine("Failed to find location");
base.Failed (manager, error);
}
}
I am using the latest monodevelop, monotouch, xcode and iphone SDK, just installed a coupla days ago. Any suggestions?
Regards
_Eric
The exception is saying you should not call base.Failed in the overridden "Failed" method.