Error when running the example code

Jun 4, 2013 at 10:01 PM
I am trying to run your example code and am getting the following error:
The server encountered an error processing the request. The exception message is 'Exception has been thrown by the target of an invocation.'. See server logs for more details. The exception stack trace is:

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Data.Services.DataServiceConfiguration.InvokeStaticInitialization(Type type) at System.Data.Services.DataServiceConfiguration.Initialize(Type type) at System.Data.Services.DataService`1.CreateProvider() at System.Data.Services.DataService`1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
I am running VS 2012.2 and have updated to the latest packages (EntityFramework 5.0.0). I am not used to code-first. Is there anything I should be doing to make that work (e.g. a connection string)?

As a side note, my ultimate goal is to get your provider implementation to work with a normal EF model (ObjectContext - not DbContext). I need to be able to create ServiceActions that can be called while passing parameters via the HTTP request body due to the large nature of my parameter data. I hope I'm in the right place. Thanks!
-Tim
Jun 5, 2013 at 2:38 PM
Ok - I seem to have stumbled through a couple of errors. It turns out that the example solution is quite temperamental in regards to its IIS settings. I finally got it to work with the Visual Studio Development Server and temporarily changing the Initializer from DropCreateDatabaseIfModelChanges to DropCreateDatabaseAlways.

However, my root problem still exists. How can I get this provider to work with ObjectContext rather than DbContext? Using your provider implementation project as-is with only the following change...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace ActionProviderImplementation
{
    public class EntityFrameworkActionProvider : ActionProvider
    {
        ObjectContext _objectContext;

        public EntityFrameworkActionProvider(ObjectContext objectContext)
            : base(objectContext, new EntityFrameworkParameterMarshaller())
        {
            _objectContext = objectContext;
        }
    }
}
...renders the following error...
Unable to cast object of type 'ActionProviderImplementation.EntityFrameworkActionProvider' to type 'System.Data.Services.Providers.IDataServiceActionProvider'

at System.Data.Services.WebUtil.GetService[T](Object target) at System.Data.Services.Providers.DataServiceProviderWrapper.GetService[T]() at System.Data.Services.Providers.DataServiceActionProviderWrapper.TryLoadActionProvider() at System.Data.Services.Providers.DataServiceActionProviderWrapper.GetServiceActions() at System.Data.Services.Providers.DataServiceProviderWrapper.<GetVisibleOperations>d__1a.MoveNext() at System.Data.Services.Providers.DataServiceProviderWrapper.<GetVisibleTypes>d__b.MoveNext() at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) at System.Data.Services.Providers.DataServiceProviderWrapper.PopulateMetadataCacheItemForBuiltInProvider() at System.Data.Services.DataService`1.CreateProvider() at System.Data.Services.DataService`1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Any sage-like advice you can provide will be much appreciated!
Mar 13, 2014 at 4:40 PM
I'm having the same problem.

'Unable to cast object of type 'ActionProviderImplementation.EntityFrameworkActionProvider' to type 'System.Data.Services.Providers.IDataServiceActionProvider'

Did you ever resolve this?

Anyone using this successfully? I'm surprised at the lack of posts out there on Actions in general.