Mobile Iron build crash while rendering UITextview control - iphone

We have an strange issue on Mobile Iron iOS devices, the application crashes each time while loading screen containing UITextview control, Other screen works fine.
The application works perfectly fine when installed on non mobile iron device.
Thanks in advance for providing any help in further debugging this issue.
More information:
Below is the crash log snippet:
13/08/2018 07:14:26 AM - MOB_APPLICATION - Error Description: Error in AddControl with WizardAttributeId = 688 due to = , Message :The ObjectiveC class 'ACTextViewDelegateProxy' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject)., StackTrace : at MOB_APPLICATION.iOS.CustomControls.TextViewControl.configureTextView (System.String controlLabel) <0x104b04b50 + 0x00dd0> in <43ca0360be2c4376b18eba301a6ce7cc#2d993c574819398378e4eeb47a646433>:0
at MOB_APPLICATION.iOS.CustomControls.TextViewControl..ctor (MOB_APPLICATION.Shared.Model.WizardAttribute model, System.Int64 assetID, UIKit.UIViewController controller, System.String controlLabel) <0x104b04800 + 0x001f3> in <43ca0360be2c4376b18eba301a6ce7cc#2d993c574819398378e4eeb47a646433>:0
at MOB_APPLICATION.iOS.CustomControls.Control.AddControl (MOB_APPLICATION.Shared.Model.WizardAttribute attributeModel, System.Int32& controlHeight, UIKit.UIViewController controller, System.Int64 assetID, System.Boolean isAttrHistoryTime, System.Boolean isGrid, System.String controlLabel) <0x104ad45d0 + 0x014f7> in <43ca0360be2c4376b18eba301a6ce7cc#2d993c574819398378e4eeb47a646433>:0 DeviceInfo: iPhone | 11.4.1 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXX | 1.0.74.2v
13/08/2018 07:14:26 AM - MOB_APPLICATION - Error Description: Error in configureTextView with WizardAttributeId = 688 due to = , Message :The ObjectiveC class 'ACTextViewDelegateProxy' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject)., StackTrace : at Registrar.DynamicRegistrar.Lookup (System.IntPtr class, System.Boolean throw_on_error) <0x105002880 + 0x001e8> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at ObjCRuntime.Class.Lookup (System.IntPtr klass, System.Boolean throw_on_error) <0x105022b30 + 0x00033> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at ObjCRuntime.Class.Lookup (System.IntPtr klass) <0x105022b00 + 0x00017> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at ObjCRuntime.Runtime.ConstructNSObject (System.IntPtr ptr, System.IntPtr klass, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution) <0x104ffb3e0 + 0x0001f> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at ObjCRuntime.Runtime.GetNSObject (System.IntPtr ptr, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution, System.Boolean evenInFinalizerQueue) <0x104ffbc30 + 0x00077> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at ObjCRuntime.Runtime.GetNSObject (System.IntPtr ptr) <0x104ffbc00 + 0x0001b> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at UIKit.UITextView.get_WeakDelegate () <0x104fec7f0 + 0x0006b> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at UIKit.UITextView.get_Delegate () <0x104fea980 + 0x0001f> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at UIKit.UITextView.EnsureUITextViewDelegate () <0x104feccf0 + 0x0001b> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at UIKit.UITextView.get_ShouldBeginEditing () <0x104fecf50 + 0x00013> in <b7935acd70e343049845d6fd73e5ec44#2d993c574819398378e4eeb47a646433>:0
at MOB_APPLICATION.iOS.CustomControls.TextViewControl.configureTextView (System.String controlLabel) <0x104b04b50 + 0x00793> in <43ca0360be2c4376b18eba301a6ce7cc#2d993c574819398378e4eeb47a646433>:0 DeviceInfo: iPhone | 11.4.1 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXX | 1.0.74.2v
What is "Message :The ObjectiveC class 'ACTextViewDelegateProxy' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject)" about in above stack trace .
The app. is build upon Xamarin.iOS platform.

Related

What do Get-WMIObject \ Get-CimInstance actually do?

I have developing a new WMI instance provider and I am having a bit of trouble. I am able to register my provider successfully using regsvr32.exe. The regsvr32 application calls my implementation of DllRegisterServer and creates the following registry keys and values:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00000001-0000-0000-0000-00000000000F} : (default) = "WMI Provider"
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00000001-0000-0000-0000-00000000000F}\InprocServer32 : (default) = "C:\MyWmiProvider.dll"
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00000001-0000-0000-0000-00000000000F}\InprocServer32 : ThreadingModel = Neutral
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{00000001-0000-0000-0000-00000000000F}\Version : (default) = 1.0.0
(Where {00000001-0000-0000-0000-00000000000F} is just a test Class ID (CLSID))
I am also able to successfully add my WMI class definitions defined in my Managed Object Format (MOF) file by using mofcomp.exe. I am able to verify that my definitions are present in the WMI repository by running the following command:
Get-CimClass -Namespace "root/MyNamespace" | Where-Object CimClassName -like "MyClass_*"
Here is an example of what my MOF file looks like:
#pragma namespace("\\\\.\\root\\MyNamespace")
#pragma autorecover
instance of __Win32Provider as $P
{
Name = "MyWmiProvider";
ClsId = "{00000001-0000-0000-0000-00000000000F}";
};
instance of __InstanceProviderRegistration
{
Provider = $P;
SupportsGet = FALSE;
SupportsPut = FALSE;
SupportsDelete = FALSE;
SupportsEnumeration = TRUE;
};
[dynamic, provider("MyWmiProvider")]
class MyClass_ExampleName
{
[key]
uint14 Id;
[PropertyContext("Name")]
String Name;
};
Now, if I run the following:
Get-CimInstance -Namespace "root/MyNamespace" -Class "MyClass_ExampleName"
This produces the following error in PowerShell:
Get-CimInstance : Provider load failure
At line:1 char:1
+ Get-CimInstance -Namespace "root/MyNamespace" -Class "MyClass_ExampleName"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (root/Surface:Device_Status:String) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041013,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
Likewise, there are three (3) Event Viewer logs that are generated when this command is executed:
MyWmiProvider provider started with result code 0x80041013. HostProcess = wmiprvse.exe; ProcessID = 2144; ProviderPath = C:\MyWmiProvider.dll
Id = {FB6B3CF7-293E-0002-9316-73FB3E29D601}; ClientMachine = RTR-USERNAME; User = MYDOMAIN\username; ClientProcessId = 19416; Component = Unknown; Operation = Start IWbemServices::CreateInstanceEnum - root\MyNamespace : MyClass_ExampleName; ResultCode = 0x80041013; PossibleCause = Unknown
MyWmiProvider provider started with result code 0x80041013. HostProcess = wmiprvse.exe; ProcessID = 24636; ProviderPath = C:\MyWmiProvider.dll
(It is shown that WMI did find the DLL correctly)
I get similar results if I try calling Get-WMIObject, except the second Event Viewer log says the "Operation" was "Start IWbemServices::ExecQuery - root\MyNamespace : MyClass_ExampleName".
What exactly are Get-WMIObject and Get-CimInstance doing in the background?
I have looked up the source for Get-WMIObject [here] and despite the simple 6 lines, looking up the respect classes and function calls does not yield detailed specifics. My DLL interface only includes four (4) exported functions: DllGetClassObject(), DllCanUnloadNow(), DllRegisterServer(), and DllUnregisterServer(). I thought both Get-WMIObject and Get-CimInstance first made a call to DllGetClassObject() in order to get the WMI class factory, however if I place a function call to save a string to a temporary file within DllGetClassObject(), I notice when calling these PowerShell commands that no temporary file is created.
I got even more specific by creating a new project following this answer so that I could be able to call the following:
DEFINE_GUID(InstanceProviderClassID, 0x00000001, 0x00000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F);
IWbemServices * pLoc = NULL;
CoCreateInstance(InstanceProviderClassID, NULL, CLSCTX_INPROC_SERVER, IID_IWbemServices, (LPVOID *)&pLoc);
The call to CoCreateInstance() in this case was successful. I even noticed the temporary log file was created, indicating that DllGetClassObject() was in fact called!
Even if I take a working instance provider that I have and put this same printing statement (or similarly a call to create a registry key/value) in its DllGetClassObject() function, nothing is ever saved to indicate that this function is called when calling these PowerShell commands.
1. What am I missing here?
2. Why is the DllGetClassObject() function never called when executing both Get-WMIObject and Get-CimInstance?
3. Why am I able to execute CoCreateInstance() successfully, demonstrating my provider is coded correctly, but get a "provider load failure" when executing one of the PowerShell commands?
(A side note: In order to make things easy, I have labeled all service functions with WBEM_E_NOT_SUPPORTED. When this is done in the working instance provider, I still do not see "provider load failure," but rather "not supported.")
Get-CimInstance and Get-WmiObject both use .NET APIs to communicate with WMI. In the first case, it uses https://learn.microsoft.com/en-us/dotnet/api/microsoft.management.infrastructure and in the latter case uses https://learn.microsoft.com/en-us/dotnet/api/system.management. The main difference between these two is that the CIM APIs are cross-platform compatible, while the WMI APIs have Windows extensions to CIM that only work on Windows.
Whether you decide to use the PowerShell cmdlets, WMIC, wbemtest, or something else, they ultimately call the WMI COM API https://learn.microsoft.com/en-us/windows/win32/wmisdk/com-api-for-wmi to talk to WMI to talk to WMI Providers.
Did you follow https://learn.microsoft.com/en-us/windows/win32/wmisdk/writing-an-instance-provider? It doesn't seem like you may have implemented IWbemServices in your COM server?

DirectoryNotFoundException: Could not find a part of the path. (C# - Unity)

I am trying to save some simple user data, following this tutorial. I am building for Android.
On the first compilations, everything worked fine. However - I came back to my project today and I got the following error: (I have done some work since then, but I cannot think what has changed to cause the problem).
DirectoryNotFoundException: Could not find a part of the path
"C:\Users\Ben\AppData\LocalLow\Top Notch Development\Simple Swim\Log:71.test".
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:292)
System.IO.FileStream..ctor (System.String path, FileMode mode)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode)
SaveSessionSystem.SaveSessionData (.InputController inputcontroller) (at Assets/Scripts/Saving Stuff/SaveSessionSystem.cs:25)
InputController.SaveSessionData () (at Assets/Scripts/InputController.cs:152)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
The reason its 'Log71' is because every new file created is assigned a number which increments each time a new file is created.
I have tried the following solutions:
Found the persistent data path to confirm it exists.
Changed the save path to a known desktop folder.
Deleting library and temp folders.
This is the code for saving a file:
string sessionNumber = PlayerPrefs.GetInt("sessionNumberKey").ToString();
string customFileName = "/Log:" + sessionNumber + ".test";
// Save the data
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + customFileName;
FileStream stream = new FileStream(path, FileMode.Create);
SaveSession saveSessionData = new SaveSession(inputcontroller);
formatter.Serialize(stream, saveSessionData);
stream.Close();
Debug.Log("The file has been saved with the filename: " + path);
The expected result is the message 'The file has been saved with the filename: (filename)' and a new file to be created in the persistent data path (on my computer that is C:\Users\Ben\AppData\LocalLow\Top Notch Development\Simple Swim)
However, currently, I am getting the error message and no new file.
You cant have colon in file name in Windows.
You should delete colon. (:)

StackOverflowException in PowerShell when tab-completion/Intellisense is invoked

I'm writing a PowerShell module, in PowerShell, which has to redirect an assembly binding.
I had no problems using a bindingRedirect in powershell_ise.exe.config but I don't think this is acceptable for a module I want to distribute, so I looked for other ways and came across AppDomain.CurrentDomain.AssemblyResolve.
I'm currently using this at the top of my .psm1 file:
function Resolve-AssemblyRedirect {
PARAM ([object]$sender, [System.ResolveEventArgs]$e)
PROCESS {
$requestedName = New-Object System.Reflection.AssemblyName $e.Name
if ($requestedName.Name -eq "System.Net.Http.Primitives") {
return [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\Assemblies\System.Net.Http.Primitives.dll")
}
return $null
}
}
if (-not $Global:MODULE_LOADED) {
[AppDomain]::CurrentDomain.add_AssemblyResolve( { Resolve-AssemblyRedirect $Args[0] $Args[1] } )
Set-Variable -Option Constant -Name MODULE_LOADED -Value $true -Scope Global
}
I can trigger the problem fairly reliably by using tab-completion/Intellisense in the ISE. I have also seen it in the shell. When I say fairly reliably, it's not always the same cmdlet that triggers it. For example, in preparing this, I've triggered it with Get-ADUser [tab] and most recently, I typed get-por [tab], Intellisense displayed Get-GPOReport and then it hung.
If I comment-out the line beginning [AppDomain]::, and hammer tab-completion, I don't see a problem.
Before I go on, I want to point out that I've never had to debug anything in PowerShell, before, so there's been quite a bit of fumbling in the dark. In order to debug, I added a REG_SZ to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug with the name Auto and the value 1, which is giving me the option to start VS 2012. That is then showing me:
System.StackOverflowException was unhandled
and when I look at the Call Stack I see:
mscorlib.dll!System.Resources.ResourceManager.GetString(string name, System.Globalization.CultureInfo culture) + 0x23c bytes
System.Management.Automation.dll!System.Management.Automation.ErrorCategoryInfo.Ellipsize(System.Globalization.CultureInfo uiCultureInfo, string original) + 0x88 bytes
System.Management.Automation.dll!System.Management.Automation.ScriptBlock.InvokeAsDelegateHelper(object dollarUnder, object dollarThis, object[] args) + 0x137 bytes
[Lightweight Function]
mscorlib.dll!System.AppDomain.OnAssemblyResolveEvent(System.Reflection.RuntimeAssembly assembly, string assemblyFullName) + 0xbc bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(string name, System.Globalization.CultureInfo culture, System.Version version, bool throwOnFileNotFound, ref System.Threading.StackCrawlMark stackMark) + 0x3ab bytes
mscorlib.dll!System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(System.Globalization.CultureInfo lookForCulture, ref System.Threading.StackCrawlMark stackMark) + 0xdd bytes
mscorlib.dll!System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(System.Globalization.CultureInfo culture, System.Collections.Generic.Dictionary<string,System.Resources.ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref System.Threading.StackCrawlMark stackMark) + 0xe2 bytes
mscorlib.dll!System.Resources.ResourceManager.InternalGetResourceSet(System.Globalization.CultureInfo requestedCulture, bool createIfNotExists, bool tryParents, ref System.Threading.StackCrawlMark stackMark) + 0x329 bytes
mscorlib.dll!System.Resources.ResourceManager.InternalGetResourceSet(System.Globalization.CultureInfo culture, bool createIfNotExists, bool tryParents) + 0x23 bytes
mscorlib.dll!System.Resources.ResourceManager.GetString(string name, System.Globalization.CultureInfo culture) + 0x23c bytes
Microsoft.PowerShell.Editor.dll!Microsoft.VisualStudio.Language.Intellisense.Implementation.CompletionSession.Commit() + 0x285 bytes
Microsoft.PowerShell.GPowerShell.dll!Microsoft.PowerShell.Host.ISE.PowerShellTab.TabComplete(Microsoft.PowerShell.Host.ISE.ISEEditor editor, bool forward) + 0x51c bytes
Microsoft.PowerShell.GPowerShell.dll!Microsoft.PowerShell.Host.ISE.PowerShellTab.ProcessTab(object sender, System.Windows.Input.KeyEventArgs e, Microsoft.PowerShell.Host.ISE.PowerShellTab selectedPowerShellTab) + 0x167 bytes
Microsoft.PowerShell.GPowerShell.dll!Microsoft.Windows.PowerShell.Gui.Internal.BeforeDefaultKeyProcessor.KeyDown(System.Windows.Input.KeyEventArgs args) + 0x4a bytes
Microsoft.PowerShell.Editor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(object errorSource, System.Action call) + 0x26 bytes
Microsoft.PowerShell.Editor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.KeyProcessorDispatcher.Dispatch<System.Windows.Input.KeyEventArgs>(System.Action<Microsoft.VisualStudio.Text.Editor.KeyProcessor,System.Windows.Input.KeyEventArgs> action, System.Windows.Input.KeyEventArgs args) + 0x185 bytes
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x56 bytes
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x270 bytes
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) + 0x14e bytes
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) + 0x64 bytes
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x431 bytes
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0xab bytes
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawKeyboardActions actions, int scanCode, bool isExtendedKey, bool isSystemKey, int virtualKey) + 0x124 bytes
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(ref System.Windows.Interop.MSG msg, ref bool handled) + 0x20e bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(ref System.Windows.Interop.MSG msg, System.Windows.Input.ModifierKeys modifiers) + 0x213 bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessage(object param) + 0x35e bytes
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5e bytes
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x2bc bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x42 bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(ref System.Windows.Interop.MSG msg, ref bool handled) + 0x107 bytes
WindowsBase.dll!System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(ref System.Windows.Interop.MSG msg) + 0x4f bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(ref System.Windows.Interop.MSG msg) + 0x2c bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x112 bytes
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x17a bytes
Microsoft.PowerShell.GPowerShell.dll!Microsoft.Windows.PowerShell.Gui.Internal.Program.ShowMainWindow(System.Collections.Generic.List<string> filesToOpen, bool mta, bool noProfile, System.Threading.SendOrPostCallback loadedCallback) + 0x1a5 bytes
[Native to Managed Transition]
PowerShell_ISE.exe!Microsoft.Windows.PowerShell.GuiExe.Internal.GPowerShell.Main(string[] args) + 0x4d0 bytes
I've only included one repeat of the section between the lines:
mscorlib.dll!System.Resources.ResourceManager.GetString(string name, System.Globalization.CultureInfo culture) + 0x23c bytes
but that repeats a lot.
I've put this through the washer a few times and I don't always see the same results in the Call Stack. For example, sometimes the repeating part looks like this:
mscorlib.dll!System.Resources.ResourceManager.GetString(string name, System.Globalization.CultureInfo culture) + 0x23c bytes
System.Management.Automation.dll!System.Management.Automation.ErrorCategoryInfo.Ellipsize(System.Globalization.CultureInfo uiCultureInfo, string original) + 0x88 bytes
System.Management.Automation.dll!System.Management.Automation.ScriptBlock.InvokeAsDelegateHelper(object dollarUnder, object dollarThis, object[] args) + 0x137 bytes
[Lightweight Function]
mscorlib.dll!System.AppDomain.OnAssemblyResolveEvent(System.Reflection.RuntimeAssembly assembly, string assemblyFullName) + 0xbc bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(string name, System.Globalization.CultureInfo culture, System.Version version, bool throwOnFileNotFound, ref System.Threading.StackCrawlMark stackMark) + 0x3ab bytes
mscorlib.dll!System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(System.Globalization.CultureInfo lookForCulture, ref System.Threading.StackCrawlMark stackMark) + 0xdd bytes
mscorlib.dll!System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(System.Globalization.CultureInfo culture, System.Collections.Generic.Dictionary<string,System.Resources.ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref System.Threading.StackCrawlMark stackMark) + 0xe2 bytes
mscorlib.dll!System.Resources.ResourceManager.InternalGetResourceSet(System.Globalization.CultureInfo requestedCulture, bool createIfNotExists, bool tryParents, ref System.Threading.StackCrawlMark stackMark) + 0x329 bytes
mscorlib.dll!System.Resources.ResourceManager.InternalGetResourceSet(System.Globalization.CultureInfo culture, bool createIfNotExists, bool tryParents) + 0x23 bytes
mscorlib.dll!System.Resources.ResourceManager.GetString(string name, System.Globalization.CultureInfo culture) + 0x23c bytes
while the initial part before the repeat starts is often different.
From a bit of reading, it seems that LightweightFunction is probably my function Resolve-AssemblyRedirect.
Am I doing something wrong?
Without digging into the AppDomain assembly resolution stuff, I can tell that you that most likely there is a non-terminating loop in the code path represented by the repeating lines in the stack walk. Each time the code goes through the loop it eats up more stack until all the stack's been used and you get the exception with the same name as this web site.
My guess is that the change you made to the .config file causes .NET to behave badly.
Using reflector I can see the infinite loop. InvokeAsDelegateHelper calls GetContextFromTLS. GetContextFromTLS calls GetExecutionContextFromTLS. GetExecutionContextFromTLS returns null if the DefaultRunspace is null. When GetContextFromTLS gets a null back from GetExecutionContextFromTLS (among other things) it calls ErrorCategory.Ellipsize. Ellipsize reads the property ErrorPackage.Ellipsize. The ErrorPackage.Ellipsize accessor method calls ResourceManager.GetString, which restarts the loop
So it looks like the bad behavior comes from having a null DefaultRunspace. I'm not sure how that would happen if you are just using Powershell.exe to run your script. But if you are invoking Powershell from, say, C#, then you probably have a bug in your code that invokes Powershell. Either way it would probably be helpful to look on MSDN at the documentation regarding launching Powershell from a program.
HTH
$e.Name contains not only the assembly name, but also version info, etc. like
System.IO.Abstractions, Version=2.1.0.178, Culture=neutral, PublicKeyToken=96bf224d23c43e59
so your name comparison and dll loading would never work.
I've encountered the same problem yesterday, it turns out that a bug in name comparison and resolving failed for some assemblies like System.Management.Automation.resources.dll in some cases, which caused resolving retried again and again, and finally crashed for stack overflow.
besides, in my case, put add_assemblyResolve function call before calling add-type could also cause the same problem.

FakeItEasy ReturnsLazily with out parameter

I'm new to using FakeItEasy and rather stuck at my first attempt. The interface i want to fake has a method like this:
byte[] ReadFileChunk(string path,int offset,int count,out long size);
I would like to see how the arguments are passed on, so I'm using ReturnsLazily. Here is my attempt:
long resSize;
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily((string path, int offset, int count) =>
{
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
.AssignsOutAndRefParameters(123);
This compiles, but when ran it generates this exception:
The faked method has the signature (System.String, System.Int32, System.Int32, System.Int64&), but returns lazily was used with (System.String, System.Int32, System.Int32).
Which is correct, but i can't figure out how to add the out parameter. If I change the ReturnLazily part to this:
.ReturnsLazily((string path, int offset, int count, out long size) =>
{
size = 0;
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
it will not compile, and I don't understand the errors:
error CS1593: Delegate 'System.Func<FakeItEasy.Core.IFakeObjectCall,byte[]>' does not take 4 arguments
error CS1661: Cannot convert lambda expression to delegate type 'System.Func<string,int,int,long,byte[]>' because the parameter types do not match the delegate parameter types
error CS1677: Parameter 4 should not be declared with the 'out' keyword
For a novice like me, this reads like it doesn't like 4 parameters nor understands what to do with 'out'. Can someone please explain me how I should be reading these errors? A working example would be very welcome as well :-)
Thanks a lot!
--- EDIT ---
This seems to work:
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily(x =>
Encoding.UTF8.GetBytes("You requested: " + x.Arguments.Get<string>(0) + "(" + x.Arguments.Get<int>(1) + "," + x.Arguments.Get<int>(2) + ")"))
.AssignsOutAndRefParameters((long)123);
A bit less readable then I was hoping for, is this anywhere near the intended use of ReturnsLazily?
Is that interface under your control?
byte[] ReadFileChunk(string path, int offset, int count, out long size);
if so: Isn't out long size just the same as the size of the returning byte[]?
In that case I would just remove the size parameter from the interface method and use the "nice-to-read" ReturnsLazily method as you intended first.
Update: the issue I mention below was fixed in FakeItEasy release 1.15, so update to the latest version and you shouldn't have to worry about the out/ref specifiers on the methods when using ReturnsLazily.
Sorry for the delay. I'm glad you found a solution that at least functions for you.
I agree that the syntax you landed on isn't the most readable, but it does appear to be the correct one. The "convenience" versions of ReturnsLazily won't work with out/ref parameters because the lambda can't take the out/ref modifiers.
It doesn't help you today, but I've created FakeItEasy issue 168 to deal with the problem. If you have additional opinions, please drop by and comment or something.

Monotouch PInvoke System.EntryPointNotFoundException

I've embedded some C# code into an iphone objective-c app using monotouch. I'm able to call into the C# code and get a return value, but I am not able to invoke a C function from the C# code using PInvoke. I am attempting to get a trivial example working. It is a simple calculator. The objective c code calls into the C# code to add two integers. The C# code should then call back into the objective-c code and give it the updated value. Below is the C# code that handles the calculation:
public class MyClass
{
static public void Add(int a, int b)
{
updateResult(a + b);
}
[DllImport("__Internal", EntryPoint="updateResult")]
static extern public void updateResult(int result);
}
Here is my code that initializes mono and handles the add method:
#implementation Mono
- (id)init {
self = [super init];
if (self) {
NSBundle *main = [NSBundle mainBundle];
NSString *path = [main bundlePath];
const char *c_path = [path UTF8String];
[main autorelease];
[path autorelease];
chdir (c_path);
setenv ("MONO_PATH", c_path, 1);
setenv ("MONO_XMLSERIALIZER_THS", "no", 1);
setenv ("DYLD_BIND_AT_LAUNCH", "1", 1);
setenv ("MONO_REFLECTION_SERIALIZER", "yes", 1);
#if defined (__arm__)
mono_aot_register_module (mono_aot_module_mscorlib_info);
mono_aot_register_module (mono_aot_module_Math_info);
mono_jit_set_aot_only (TRUE);
#endif
mono_jit_init("MonoTouch");
MonoAssembly *assembly = mono_assembly_open("Math.dll", NULL);
MonoImage *img = mono_assembly_get_image(assembly);
MonoClass *cls = mono_class_from_name(img, "Math", "MyClass");
MonoMethodDesc *methodDesc = mono_method_desc_new("Math.MyClass:Add", TRUE);
_addMethod = mono_method_desc_search_in_class(methodDesc, cls);
}
return self;
}
- (void)addA:(int)a plusB:(int)b {
void *params[] = { &a, &b };
mono_runtime_invoke(_addMethod, NULL, params, NULL);
}
#end
and here is the definition of the updateResults method:
extern void updateResult(int result) {
printf("Got Result");
}
When the updateResults is called from the C# side of things I get the following exception:
Unhandled Exception: System.EntryPointNotFoundException: updateResult
at (wrapper managed-to-native) Math.MyClass:updateResult (int)
at Math.MyClass.Add (Int32 a, Int32 b) [0x00000] in <filename unknown>:0
I can see the symbol in the binary with the following command:
$ nm Calc | grep updateResult
00002b2e t _updateResult
Setting the MONO_LOG_LEVEL environment variable to debug I get the following output when attempting the PInvoke. It looks like it finds the method and then can't find it:
Mono: DllImport attempting to load: '_Internal'.Mono: Searching for 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResultA'.Mono: Probing 'updateResultA'.Mono: DllImport attempting to load: '_Internal'.Mono: Searching for 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResultA'.Mono: Probing 'updateResultA'.Mono: AOT FOUND AOT compiled code for (wrapper managed-to-native) Math.MyClass:updateResult (int) 0x3bc8 - 0x3d90 0x3dcb
Mono: DllImport attempting to load: '__Internal'.Mono: Searching for 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResult'.Mono: Probing 'updateResultA'.Mono: Probing 'updateResultA'.Unable to resolve pinvoke method 'Math.MyClass:updateResult (int)' Re-run with MONO_LOG_LEVEL=debug for more information.
I've spent quite some time trying to figure this out. From what I've read it seems like this should be pretty trivial, but I can't get it to work. Any help would be much appreciated.
Would it be better to use Selectors?
That is the default path to follow as suggested by the makers of MonoTouch.
It could be a few things, but my first guess is that you aren't using the C symbol from anywhere in native code, and the DCE (dead code elimination) pass is removing it. Try disabling DCE in your Xcode project options.
I've had this problem myself, if you compare an objdump -T and objdump -t of your binary,
you'll find that the "D" flag is missing, so add a -rdynamic to your linker options.