question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with Xamarin.iOS

See original GitHub issue

I’ve been working on a .NET Standard 2.0 library for a while now, an using Scrutor with FromApplicationDependencies() has been working fine in my unit tests.

However, when Scrutor is used in Xamarin.iOS both FromApplicationDependencies() and FromDependencyContext(DependencyContext.Load(Assembly.GetEntryAssembly())) throw an exception:

The type initializer for 'Microsoft.Extensions.DependencyModel.DependencyContextLoader' threw an exception.

...

System.NotImplementedException: The method or operation is not implemented.

...

  at System.AppContext.GetData (System.String name) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.18/src/mono/mcs/class/referencesource/mscorlib/system/AppContext/AppContext.cs:46 
  at Microsoft.Extensions.DependencyModel.DependencyContextPaths.GetCurrent () [0x00000] in <8241b70107294c1cb31f55eb9c49a4a8>:0 
  at Microsoft.Extensions.DependencyModel.DependencyContextPaths..cctor () [0x0000a] in <8241b70107294c1cb31f55eb9c49a4a8>:0 

I tried getting around this by doing the following:

var entryAssembly = Assembly.GetEntryAssembly();
var entryDependencyAssemblies = entryAssembly.GetReferencedAssemblies();
List<Assembly> scanAssemblies = new List<Assembly> { entryAssembly };
foreach (var assemblyName in entryDependencyAssemblies)
{
    var assembly = Assembly.Load(assemblyName);
    scanAssemblies.Add(assembly);
}

...

.FromAssemblies(scanAssemblies)

Unfortunately Scrutor is not finding any classes when I do this. Not sure if it matters, but I specify an array of base types that I scan for, like this:

.AddClasses(classes => classes.Where(c => scanTypes.Contains(c.BaseType)))

Note that the debugger is showing that scanAssemblies does contain the correct assemblies, and I can see the types I want under DefinedTypes.

Even a hacky workaround would be very much appreciated at this point!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
khellangcommented, Aug 23, 2017

@Dids Pushed a new version, 2.1.0 to NuGet with a new method, FromAssemblyDependencies, that does more or less what your code above does. FromApplicationDependencies will now also fall back to this method, using the entry assembly when the DependencyContext fails to load, i.e. on Xamarin/Mono.

0reactions
khellangcommented, Feb 14, 2018

I’m closing this due to lack of activity. I’m assuming everything sorted itself out with the new methods 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · xamarin/Xamarin.Forms
Xamarin forms UI Elements bug after returning from a website. #15748 opened on May 22 by vsfeedback · [Bug] Find element by automation...
Read more >
Troubleshooting Tips for Xamarin.iOS
This document provides various tips useful for troubleshooting during the development of Xamarin.iOS applications.
Read more >
Connection Troubleshooting for a Xamarin.iOS Build Host
This guide provides troubleshooting steps for issues that may be encountered using the new connection manager, including connectivity and ...
Read more >
Xamarin iOS Compatibility Issues with latest Xcode 15
Specifically, I am facing pairing issues with both IDEs, as no iOS simulators are available for debugging and I am unable to open...
Read more >
Xamarin iOS in Visual Studio 2022 - Problem with ...
In VS 2019 there was an issue on iOS with provision profiles, that is fixed now in VS 2022 17.0.1 but now a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found