Castle Windsor Castle.MicroKernel.ComponentRegistrationException - inversion-of-control

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

Related

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

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.

Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is "AspNetSqlRoleProvider"

I have a MVC 5 project using ASP.NET Identity (Invidual user account). As Database ORM I am using Entity framework 6 and IoC is taken care by Ninject.
Solution structure is following
MVC project
-- has my controllers, views and ninject setup. For Ninject I got Ninject.MVC3 from nuget.
Data project
--- has my DataContext (IdentityDbContext) and my ApplicationUser (IdentityUser). My
Data services and all repositories
Core project
-- has all my entities and interfaces
[Authorize] attribute works fine and I have to login to access tha annotated action, but when I set [Authorize(Roles = "Admin")] I get
Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
I created my on CustomAuthorize attibute which was basically a copy of Authorize and noticed that the
httpcontext in protected virtual bool AuthorizeCore(HttpContextBase httpContext) User.ProviderName is "AspNetSqlRoleProvider".
So I added Rolemanages clear to my web.config. This resulted in
Configuration Error Description: An error occurred during the
processing of a configuration file required to service this request.
Please review the specific error details below and modify your
configuration file appropriately.
Parser Error Message: Default Role Provider could not be found.
Source Error:
Line 53: --> Line 54: Line 55: Line
56: Line 57:
Source File:
...myproject\WebUI\web.config
Line: 55
So whats the deal here? How can I set the Default Role Provider to use ASP.NET Identity?
So right after I posted the question I figured the answer. I had to add
<system.webServer>
<modules>
...
<remove name="RoleManager" />
</modules>
</system.webServer>
That did it. But there still is a question of why?

Connect to a running JBoss AS7 instance for test purposes

I already have a integration-test phase, when I ran the selenium tests. I also want to run some unit tests in this phase, because the app is too much complex and have a lot of dependencies between his modules (a hell), so, after a week fighting against OpenEJB and Arquillian, I believe that this would be easier.
The thing is: how do I made it work?
I have the instance already running, if I instantiate an InitialContext and try to lookup some bean, I got an exception telling me that I have not set the java.naming.initial.factory, and I don't know what to put in there.
I'm also complaining about the annotated beans.
Suppose a Bean like this:
#Stateless
public class ABeanImpl implements ABean {
#EJB
private BBean;
}
Will the container automatically get right the BBean?
Thanks in advance
How to connect to JBoss 7.1 remote JNDI:
Here is the code snippet that I use for JBoss 7.1:
Properties props = new Properties();
String JBOSS_CONTEXT = "org.jboss.naming.remote.client.InitialContextFactory";
props.put("jboss.naming.client.ejb.context", true);
props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "jboss");
props.put(Context.SECURITY_CREDENTIALS, "jboss123");
InitialContext ctx = new InitialContext(props);
Resolution of ambiguous ejb references:
According to JBoss EJB 3 reference, if at any level of your EJB environment (EJB/EAR/Server) are duplicates in used interfaces, exception will be thrown during resolution of injected beans.
Based on above, if you have got a reference to EJB bean which interface:
has two implementations in your EJB module (JAR/WAR) - exception will be thrown
has two implementations in your application (other EJB JAR's in same EAR) - exception will be thrown
has two implementations, one in module with bean ABeanImpl, second somewhere else - implemetation from current module is used.

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]

Code-First Entity Framework - error creating SQL CE DB

I have been using Entity Framework CTP with Code-First as in this tutorial by Scott Guthrie and another by Scott Hanselman (can't post the link, but google "Simple Code First with Entity Framework 4 - Magic Unicorn Feature CTP 4"). This is working perfectly for the main MVC application, but I am now trying to add a testing project, that uses a separate SQL CE Database.
I have added the following to the App.Config file:
<connectionStrings>
<add name="MyData"
connectionString="Data Source=D:\myProject\myDb.sdf;"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
However when I try to run the tests it throws the following error when trying to create the database:
Test method
MyProjet.Tests.Administration.ModlelTests.Business.TestGetBusinessesList
threw exception:
System.Reflection.TargetInvocationException:
Exception has been thrown by the
target of an invocation. --->
System.TypeInitializationException:
The type initializer for
'System.Data.SqlServerCe.SqlCeProviderServices'
threw an exception. --->
System.Security.VerificationException:
Operation could destabilize the
runtime.
With the following stack trace:
System.Data.SqlServerCe.SqlCeProviderServices..ctor()
System.Data.SqlServerCe.SqlCeProviderServices..cctor()
System.RuntimeFieldHandle.GetValue(RtFieldInfo
field, Object instance, RuntimeType
fieldType, RuntimeType declaringType,
Boolean& domainInitialized)
System.Reflection.RtFieldInfo.InternalGetValue(Object
obj, Boolean doVisibilityCheck,
Boolean doCheckConsistency)
System.Reflection.RtFieldInfo.InternalGetValue(Object
obj, Boolean doVisibilityCheck)
System.Reflection.RtFieldInfo.GetValue(Object
obj)
System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance_GetValue()
System.Data.SqlServerCe.ExtensionMethods.SystemDataSqlServerCeSqlCeProviderServices_Instance()
System.Data.SqlServerCe.SqlCeProviderFactory.System.IServiceProvider.GetService(Type
serviceType)
System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory
factory)
System.Data.Common.DbProviderServices.GetProviderServices(DbConnection
connection)
System.Data.Entity.ModelConfiguration.Internal.Configuration.CodeFirstCachedMetadataWorkspace.GetMetadataWorkspace(DbConnection
storeConnection)
System.Data.Entity.Infrastructure.DbModel.CreateObjectContext[TContext](DbConnection
existingConnection)
System.Data.Entity.Internal.LazyInternalContext.InitializeFromModel(DbModel
model)
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
System.Data.Entity.Internal.InternalContext.Initialize()
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type
entityType)
System.Data.Entity.Internal.Linq.EfInternalQuery1.Initialize()
System.Data.Entity.Internal.Linq.EfInternalQuery1.Include(String
path)
System.Data.Entity.Infrastructure.DbQuery`1.Include(String
path)
MyProjet.Areas.Administration.Models.BusinessModel.GetBusinesses()
in
D:\projects2010\MyProjet\MyProjet\Areas\Administration\Models\BusinessModel.cs:
line 47
MyProjet.Tests.Administration.ModlelTests.Business.TestGetBusinessesList()
in
D:\projects2010\MyProjet\MyProjet.Tests\Administration\ModlelTests\Business.cs:
line 45
I have tried replacing the existing MyData connection string in the MVC application, and it works fine. It only causes this problem when this is added to the Testing project. Additionally the testing project works without problem when pointed at an SQL or SQL Express Database.
Have been struggling with this for a while now, and just can't figure it out. I am sure I have overlooked something simple.
Try using
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
See my blog post for an example http://www.arrangeactassert.com/code-first-entity-framework-unit-test-examples/
I have been running the tests under the Built in Microsoft testing framework. Changing the test framework to NUnit (as in Jag's tutorial) has fixed the problem.
So looks like there is a conflict between SqlServerCe and the Visual Studio Unit Testing Framework.