Ninject "No parameterless constructor defined for this object." - ninject

I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget.
So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller.
I did the necessary steps :
Nuget installation
in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method.
In my homecontroller I set my object like this :
public ISurvey _survey { get; set; }
[Inject]
public HomeController(ISurvey s)
{
_survey = s;
}
And I get the following error message :
Server Error in '/' Application.
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +110
[InvalidOperationException: An error occurred when trying to create a controller of type 'Surveys.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +226
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +326
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +177
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
So I wonder what did I do wrong ? 4 Hours on it, I found that there may be a problem with my web.config file or that It could be a reference missing, or it could be a factory missing. Right now I don't even know what to do. Thanks for your help.

You must also install Ninject.MVC3 (https://www.nuget.org/packages/Ninject.MVC3/) which includes the Ninject Controller Factory, that takes care of instantiating the controllers and injecting the right dependencies into the controller constructor. I am almost certain that if you install Ninject.MVC3 through Nuget, everything gets configured automaticaly.
Without this package, MVC uses its default controller factory, that knows nothing about injecting dependencies.

Check if in your Web.config you have two lines for MVC versioning, I had something like:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
If you do then replace them with one line like, to redirect to highest version that you are using in my case it's 4.0.0.1:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
This did it for me.

Related

DbProviderFactory CreateConnection Fails for System.Data.SqlClient

Here is the code to test with. Create a new Form, add a button and put this code in the button.
Dim dbf As Data.Common.DbProviderFactory
'
' uncomment one of the below dbf =
'
'this fails
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.SqlClient")
'these work
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.Odbc")
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb")
Dim conn As Data.Common.DbConnection
conn = dbf.CreateConnection
The create connection only fails for SqlClient. The error is
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnection
StackTrace:
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlClientFactory.CreateConnection()
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\dewayne.basnett\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 19
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=Failed to read the configuration section for enclave providers. Make sure the section is correctly formatted in your application configuration file. Error Message: Configuration system failed to initialize
Source=System.Data
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException: System.Configuration.ConfigurationErrorsException
BareMessage=Configuration system failed to initialize
HResult=-2146232062
Line=0
Message=Configuration system failed to initialize
Source=System.Configuration
StackTrace:
at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
at System.Configuration.Internal.InternalConfigRoot.OnConfigRemoved(InternalConfigEventArgs e)
at System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Data.SqlClient.SqlConnection..cctor()
InnerException: System.Configuration.ConfigurationErrorsException
BareMessage=Unrecognized configuration section userSettings.
Filename=C:\Users\dewayne.basnett\AppData\Local\WindowsApplication1\WindowsApplication1.vshos_Url_odwpvb4iq0tpdwxwwhwkttkzifz10zja\1.0.0.0\user.config
HResult=-2146232062
Line=3
Message=Unrecognized configuration section userSettings. (C:\Users\dewayne.basnett\AppData\Local\WindowsApplication1\WindowsApplication1.vshos_Url_odwpvb4iq0tpdwxwwhwkttkzifz10zja\1.0.0.0\user.config line 3)
Source=System.Configuration
StackTrace:
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
InnerException:
EDIT: The config file is created by the IDE, but FWIW here it is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<WindowsApplication1.My.MySettings>
<setting name="AutoIncrement" serializeAs="String">
<value>False</value>
</setting>
</WindowsApplication1.My.MySettings>
</userSettings>
</configuration>
App.config contents
'FAILING
'<?xml version="1.0" encoding="utf-8"?>
'<configuration>
' <startup>
' <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
' </startup>
'</configuration>
'WORKING
'<?xml version="1.0" encoding="utf-8"?>
'<configuration>
' <configSections>
' <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
' <section name="WindowsApplication1.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
' </sectionGroup>
' </configSections>
' <startup>
' <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
' </startup>
' <userSettings>
' <WindowsApplication1.My.MySettings>
' <setting name="foo" serializeAs="String">
' <value/>
' </setting>
' </WindowsApplication1.My.MySettings>
' </userSettings>
'</configuration>
The answer, and I am not sure of the mechanics behind this, is...
Yesterday a user in another domain was trying to install one of my apps and setup was throwing an error. It looked like a permission problem but they insisted it was not. One of their programmers suggested that I change the properties of a code file from Do not copy to Copy always. I didn't think it would help, but they insisted. Eventually I figured out that it was how they were mapping to the install directory.
They had it as \fileserver.mo.gov\install. Changing it to \fileserver\install fixed the problem. I did not change the code file back.
As this problem became more bizarre I thought of what happened yesterday and remembered the change. I set it back to Do not copy, republished the app, and the above problem went away. As I said I don't understand the mechanics behind this, but my issue is resolved.

Could not load file or assembly 'MvcSiteMapProvider

I added the provider via nuget console Install-Package MvcSiteMapProvider.MVC4.
The install looked good:
Successfully added 'MvcSiteMapProvider.MVC4 4.6.22' to XYZ.
When I execute the application I get this error message any suggestions on troubling shooting?
Server Error in '/XYZ' Application.
Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) +0
System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs) +38
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +571
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean inherit) +37
Owin.Loader.DefaultLoader.SearchForStartupAttribute(String friendlyName, IList1 errors, Boolean& conflict) +106
Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList1 errors) +46
Owin.Loader.DefaultLoader.LoadImplementation(String startupName, IList1 errorDetails) +75
Owin.Loader.DefaultLoader.Load(String startupName, IList1 errorDetails) +21
Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +534
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'MvcSiteMapProvider, Version=4.6.22.0, Culture=neutral, PublicKeyToken=1923abe4657913cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9947380
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
Assuming you actually have the Nuget package installed, that error is most usually an issue with binding redirects in your Web.config. You can try to resolve the issue manually, by finding the appropriate binding redirect and making sure the version numbers are correct. I find it easier to just force remove the package and reinstall it. That will usually fix the problem:
> uninstall-package MvcSiteMapProvider.MVC4 -Force
> install-package MvcSiteMapProvider.MVC4
Make sure your Web.config is not open in your documents pane, or if it is, that you allow it to reload. If you save over it without refreshing from the filesystem after installing a Nuget package, you'll often bork things like binding redirects, leading to this issue.

Why won't my MVC4 HandleErrorAttribute work?

I'm converting an MVC3 web project to MVC4. I created a ElmahHandleErrorAttribute that inherits from HandleErrorAttribute that worked fine in MVC3 and also works fine on my local dev machine, but it throws the following exception in the test environment...
[InvalidOperationException: The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.Mvc.GlobalFilterCollection.ValidateFilterInstance(Object instance) +110
System.Web.Mvc.GlobalFilterCollection.AddInternal(Object filter, Nullable`1 order) +17
System.Web.Mvc.GlobalFilterCollection.Add(Object filter) +12
Home2Me.MvcApplication.RegisterGlobalFilters(GlobalFilterCollection filters) in c:\###\Home2Me\Global.asax.cs:16
Home2Me.MvcApplication.Application_Start() in c:\###\Home2Me\Global.asax.cs:118
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9249709
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164336
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
There isn't really anything special about the class. It's pretty close to the standard one for Elmah.
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
/// <summary>
/// Called when an exception occurs.
/// </summary>
/// <param name="context"></param>
public override void OnException(ExceptionContext context)
{
base.OnException(context);
if (!context.ExceptionHandled) return; // if unhandled, will be logged anyhow
var e = context.Exception;
HandleException(e);
}
... (code snipped for brevity) ...
}
And here is the code that registers the filter in Global.asax.cs...
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
}
The filter is defined in a separate assembly that is also updated to MVC4. I have multiple projects that use this filter. One of them works fine in the test environment, and another has this same exact issue.
Any ideas on what might be wrong? I'm fairly confident that all the MVC3 references have been updated correctly in the project, including the web.config files in both the root and views directory. It does work locally and I uninstalled MVC3 and deleted all the "extra" MVC3 dlls lying around.
I believe I found an answer. I added a runtime section in the root web.config file to convert MVC3 references to MVC4.
<configuration>
... (snipped for brevity) ...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I would rather fix whatever it is that is referencing MVC3, but I can't figure out what that might be. This will have to be a good enough answer for now.

How to fix 'Access Denied' error with a .Net WCF service running on Amazon EC2?

I am new to the AWC/EC2 environment and created a .Net WCF service on my EC2 instance of Windows Server and IIS.
Navigating to http://www.websiteservice.com/MyWebsiteFeederService.svc?wsdl brings up the WSDL.
Now, in www.mywebsite.com, that is also sitting on the same machine, I have consumed the web service. Unfortunately whenever I try to access the service through the site, I continue to receive the "Access is Denied" error message:
Exception Details:
System.ServiceModel.Security.SecurityAccessDeniedException: Access is
denied.
I don't believe this is related to the AWS-S3 error - Access is Denied error, as I am not using buckets.
In the site's Web.config, I turned on the trace listener and took a look at the Service Trace Viewer.
The information doesn't seem to be useful, as this is what I get:
[TraceRecord] Severity Warning
TraceIdentifier http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx
Description Throwing an exception.
AppDomain /LM/W3SVC/4/ROOT-2-129966419874659765
Here is the full XML of Warning level:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Warning">0</SubType>
<Level>4</Level>
<TimeCreated SystemTime="2012-11-06T02:19:47.8029428Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{b6efab70-63ad-4bdd-85c6-5c49a907c210}" />
<Execution ProcessName="w3wp" ProcessID="3472" ThreadID="1" />
<Channel />
<Computer>AMAZONA-xxxxxFFR</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
<TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Throwing an exception.</Description>
<AppDomain>/LM/W3SVC/4/ROOT-2-129966419874659765</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.Security.SecurityAccessDeniedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Access is denied.</Message>
<StackTrace>
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyWebsiteFeederService.IFeederService.GetWebsiteConfiguration(String websiteGuid, String websitePW)
at MyWebsiteFeederService.FeederServiceClient.GetWebsiteConfiguration(String websiteGuid, String websitePW)
at Inquiro.Models4.ModelsBaseClass.GetWebsiteConfiguration(String websiteGuid, String websitePW)
at Inquiro.Websites.MvcApplication.LoadWebsiteConfiguration()
at Inquiro.Websites.MvcApplication.Application_Start()
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Web.HttpApplication.InvokeMethodWithAssert(MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs)
at System.Web.HttpApplication.ProcessSpecialRequest(HttpContext context, MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs, HttpSessionState session)
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
</StackTrace>
<ExceptionString>System.ServiceModel.Security.SecurityAccessDeniedException: Access is denied.</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>
I have the exact same service running on another, non-Amazon server and it is working fine. I don't recall setting up any special permissions, or "run as [user]" - have no additional users setup in IIS Manager Permissions.
I have also confirmed from the command prompt on that server, using sqlcmd, that I can connect to the RDS database server.
I'm basically going in circles at this point and would appreciate some assistance.
Thanks.
The error itself "Access is denied." isn't very helpful. Neither is the debug information.
Ultimately, in this case, the issue was that execute permissions needed to be granted to the userID that was executing the stored procedures called from the WCF service.

Ninject.MVC3 + MediumTrust = Security Exception

I created a new project of type Asp.net MVC 4
I installed the package via Ninject.MVC3 NuGet Install Package Ninject.MVC3
When running the project, security error:
Error
Server Error in '/MediumTrustSample' Application.
Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the
required permission please contact your system administrator or change
the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Security.Permissions.ReflectionPermission,
mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 20:
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule)); Line
21:
DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
Line 22: bootstrapper.Initialize(CreateKernel); Line 23:
} Line 24:
Source File: C:\Users\Riderman_2\Documents\Visual Studio
2010\Projects\MediumTrustSample\MediumTrustSample\App_Start\NinjectMVC3.cs
Line: 22
Stack Trace:
[SecurityException: Request for the permission of type
'System.Security.Permissions.ReflectionPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.]
System.Security.CodeAccessSecurityEngine.SpecialDemand(PermissionType
whatPermission, StackCrawlMark& stackMark) +0
System.Security.CodeAccessPermission.Demand(PermissionType
permissionType) +30
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks) +281
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
+38 Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition(MethodInfo
method, BindingFlags flags) in ExtensionsForMemberInfo.cs:145
Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined(PropertyInfo
element, Type attributeType, Boolean inherit) in
ExtensionsForMemberInfo.cs:173
Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo
member) in StandardInjectionHeuristic.cs:47
Ninject.Selection.<>c_DisplayClass3.b_2(IInjectionHeuristic h) in Selector.cs:92 System.Linq.Enumerable.Any(IEnumerable1
source, Func2 predicate) +149
Ninject.Selection.Selector.b_1(PropertyInfo
p) in Selector.cs:92
System.Linq.WhereEnumerableIterator1.MoveNext() +156
System.Collections.Generic.List1.InsertRange(Int32 index,
IEnumerable1 collection) +552
Ninject.Selection.Selector.SelectPropertiesForInjection(Type type) in
Selector.cs:89
Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute(IPlan
plan) in PropertyReflectionStrategy.cs:60
Ninject.Planning.<>c__DisplayClass3.<GetPlan>b__1(IPlanningStrategy s)
in Planner.cs:68
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1
series, Action1 action) in ExtensionsForIEnumerableOfT.cs:23
Ninject.Planning.Planner.GetPlan(Type type) in Planner.cs:70
Ninject.Activation.Context.Resolve() in Context.cs:180
Ninject.KernelBase.<Resolve>b__7(IContext context) in
KernelBase.cs:375
System.Linq.WhereSelectEnumerableIterator2.MoveNext() +238
System.Linq.Enumerable.SingleOrDefault(IEnumerable1 source) +299
Ninject.Planning.Targets.Target1.GetValue(Type service, IContext
parent) in Target.cs:179
Ninject.Planning.Targets.Target1.ResolveWithin(IContext parent) in
Target.cs:147
Ninject.Activation.Providers.StandardProvider.GetValue(IContext
context, ITarget target) in StandardProvider.cs:97
System.Linq.WhereSelectArrayIterator2.MoveNext() +110
System.Linq.Buffer1..ctor(IEnumerable1 source) +488
System.Linq.Enumerable.ToArray(IEnumerable1 source) +104
Ninject.Activation.Providers.StandardProvider.Create(IContext context)
in StandardProvider.cs:81 Ninject.Activation.Context.Resolve() in
Context.cs:157 Ninject.KernelBase.<Resolve>b__7(IContext context)
in KernelBase.cs:375
System.Linq.WhereSelectEnumerableIterator2.MoveNext() +238
System.Linq.d_b11.MoveNext() +296
System.Linq.Enumerable.Single(IEnumerable1 source) +282
Ninject.ResolutionExtensions.Get(IResolutionRoot root, IParameter[]
parameters) in ResolutionExtensions.cs:37
Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback)
in Bootstrapper.cs:72
MediumTrustSample.App_Start.NinjectMVC3.Start() in
C:\Users\Riderman_2\Documents\Visual Studio
2010\Projects\MediumTrustSample\MediumTrustSample\App_Start\NinjectMVC3.cs:22
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.272
Question
How to use Ninject.MVC3 with MediumTrust?
Go and get the medium trust version: https://github.com/ninject/ninject/downloads