Unable to cast object of type 'Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper' to type 'Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy' - plugins

Could anyone help me with this error?
It is happening in a Microsoft Dynamics CRM 2015 Online Plugin.
It's a late binding implementation...
Unhandled Exception:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault,
Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35]]: Unable to cast object of type
'Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper' to type
'Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy'.Detail:
-2147220891
OperationStatus
0
SubErrorCode
-2146233088
Unable to cast object of type
'Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper' to type
'Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy'.
2015-03-25T19:31:18.5408758Z
[JHSF.CRM.Principal:
JHSF.CRM.Principal.Application.Plugin.PluginAdesaoFidelidade]
[dd59ba6a-7ad1-e411-80de-c4346bb59e2c:
JHSF.CRM.Principal.Application.Plugin.PluginAdesaoFidelidade: Create
of jhsf_adesao_programa_fidelidade]
Error : Unable to cast object of type
'Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper' to type
'Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy'. StackTrace:
at SDKore.Xrm.CrmServiceProvider..ctor(String OrganizationName,
Nullable`1 IsOffline, Object Provider)

Preferably, you should not be referencing Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy in a plug-in. This is, as the word Client indicates, for client-side not server-side code.
That said, you cannot make the cast you reference above and I don't think you can create an OrganizationServiceProxy in a sandboxed plugin. If you are using early-bound entities you can create an OrganizationServiceContext - from the client DLL - by passing in the instance of IOrganizationService available to your plugin.

Related

Azure Mobile Service: Unable to load the specified metadata resource

I published my Azure Mobile Service and suddenly I got this error. I use a code first approach and I have not changed my models.
"message": "An error has occurred.",
"exceptionMessage": "Unable to load the specified metadata resource.",
"exceptionType": "System.Data.Entity.Core.MetadataException",
"stackTrace": " at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)\r\n
I m using EF 6.1.1 and my connection string is defined for the System.Data.SqlClientProvider.
It works fine when I run locally against my MSSQLLocalDB.
Anyone knows why EF attempts to load a Metadata even if I am using a code first approach? What should I do to troubleshoot the issue?
I found it, it was my connection string which was modified when the code was built in release environment. This issue was caused by a refactory.

Xamarin PCL Unhandled Exception: TargetInvocationException

Im making an mobile application which can communicate with Dynamics AX using a WCF service.
Im fairly new to Xamarin, and im trying to create a PCL library for a shared IOS and Android application. Im also working on an Windows Phone App which pretty much works by now. Im using a WCF service ive created which does all the communication with Dynamics AX, and the service exposes its methods using Metadata. I've added a Service Reference to the Windows Phone solution and the generated Proxy works like a charm, i should say im using SOAP.
But if i transfer the generated Reference.cs file to my Xamarin PCL project and call my method the exact same way i get the following error:
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Serialization.SerializationException: Expected element 'ExceptionDetail' in namespace 'http://schemas.datacontract.org/2004/07/System.ServiceModel', but found Element node 'AifFault' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/Fault'
at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x0003e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterDeserializer.cs:63
at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00024] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:363
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:76
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x0019b] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:550
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:496
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x0001c] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:477
--- End of inner exception stack trace ---
The issue only occurs when AX return an AIFFault Exception and for some reason it cant be caught by Xamarin.. Its caught just fine in Visual Studio in Windows Phone.
Here is the code from making the call:
try{
var result = await _service.ExecuteGetMethod(MyRecord)
}
catch(FaultException fe){
ShowError(fe);
}
This works just fine, and the error message from AX is showed in fe.Message, but running the exact same in Xamarin gives me the above error.
Do i need to add AIFFault somewhere in my WCF service for clients to be able to see it?

Exception thrown when opening internal browser

When I am trying to open internal web browser using
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
I get this error:
Unable to instantiate browser supportStatus ERROR:
org.eclipse.equinox.registry code=1 Plug-in "XXXXX" was unable to instantiate
class "org.eclipse.ui.internal.browser.WorkbenchBrowserSupport".
java.lang.IllegalAccessException:
Class org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI can not access a member of class org.eclipse.ui.internal.browser.WorkbenchBrowserSupport with modifiers "private"
Any idea why I get this error? Searching for error produced little hints. Debugging it shows that as error says private method is accessed through reflection.

Object.GetType throws NullReferenceExceptions

I'm trying to use Pex and Moles in my SharePoint project. However I'm facing problem when running Pex Explorations. I'm getting error:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Type System.Object.GetType()
Additionaly in "Pex Exporations result" window i'm seeing 2 Reflection issues:
System.TypeLoadException: Method 'get_TargetType' in type 'System.ComponentModel.Moles.SBaseNumberConverter' from assembly 'System.Moles, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0ae41878053f6703' does not have an implementation.
at an attribute that decorates
[module System.Moles.dll]
and
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at an attribute that decorates
[module System.Moles.dll]

Castle Windsor Castle.MicroKernel.ComponentRegistrationException

I am tring to register a fake Authentication Service for debuging using:
container.Register(Component
.For<Services.IFormsAuthenticationService>()
.ImplementedBy<Services.DebugAuthenticationService>());
where Services.DebugAuthenticationService implementes
Services.IFormsAuthenticationService
but I get this error:
Unit Test Adapter threw exception: Type is not resolved for member 'Castle.MicroKernel.ComponentRegistrationException,Castle.MicroKernel, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'..
Component for what? Implemented by what? You're missing the types.
Here you can find an example of correctly using Component.For ... ImplementedBy:
Implementing UnitOfWork with Castle.Windsor