Object.GetType throws NullReferenceExceptions - moles

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]

Related

System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception

Due to the below error i am blocked on the work.
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnectionFactory' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlPerformanceCounters' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.Common.ADP' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.Data.Common.ADP..cctor()
--- End of inner exception stack trace ---
I have dereferenced the System.Data.SqlClient in the entire project but still getting this exception.
I have added the reference for Microsoft.Data.SqlClient i even upgraded this to the latest version.[version="5.0.1" targetFramework="net472"]
I have verifying the connection string by using the VS Community DataBase TestConnection it is working fine.
We are getting this error while trying to establish connection through c# code.
.NetFramework: net472
VSCommunity editor with C# as the scripting language and Windows 11 as the OS.

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.

Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified

I'm running PowerShell from a C# console app. My dev box has PowerShell 3.0 - the target machines will probably have v2.0. My project file has a reference to the assembly:
<Reference Include="System.Management.Automation" />
which seems to be the recommended way. I'm getting a System.IO.FileNotFoundException when I call runspace.Open():
using (var runspace = RunspaceFactory.CreateRunspace(initialSessionState))
{
runspace.AvailabilityChanged += runspace_AvailabilityChanged;
runspace.StateChanged += runspace_StateChanged;
runspace.Open();
...
}
The exception details are:
Message: Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified.
FusionLog:
=== Pre-bind state information ===
LOG: User = MYDOMAIN\MyUser
LOG: DisplayName = Microsoft.PowerShell.Security
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.PowerShell.Security | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\MyUser.MYDOMAIN\Projects\PoSh\PoShRunner1\bin\Debug\PoShRunner1.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.EXE.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.EXE.
If I turn off Common Language Runtime Exceptions in VS 2012, I get
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.DllNotFoundException' occurred in System.Management.Automation.dll
A first chance exception of type 'System.Management.Automation.Host.HostException' occurred in System.Management.Automation.dll
in the output log.
I've had a look at the document referenced in the fusion log but most of it doesn't seem to apply to this case or help much with my understanding. Microsoft.PowerShell.Security is in the GAC so what's the problem?
The problem is that you compiled against the powershell 3.0 system.management.automation (s.m.a.) assembly - 3.0.0.0 - instead of the powershell 2.0 s.m.a which is 1.0.0.0.
Open your project, browse to the 1.0.0.0 version and recompile. PowerShell 3.0 installs both 1.0.0.0 and 3.0.0.0 s.m.a assemblies to the GAC. Then your program will work on systems with either 2.0 or 3.0 versions of powershell.

How to change the liferay database to mysql database

I have downloaded the liferay6 bundle with tomcat.I need to change the liferay database to mysql database.I have searched in google and as per information i have created the portal-ext.properties with below lines of code.
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root123
jdbc.default.jndi.name=jdbc/LiferayPool
schema.run.enabled=true
schema.run.minimal=true
and i modified the ROOT.xml.Now the code in that file is :
<Context path="" crossContext="true">
<Resource
name="jdbc/LiferayPool"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8"
username="root"
password="root123"
maxActive="20"
/>
</Context>
and i have created the lportal database in mysql.Do i need to modify anything more.If i do like this i am not even able to see the default login page of liferay.Can anyone point me where i am doing wrong.Thank You.
I am getting the below Exception if i am doing like this.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2744)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:148)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.portal.spring.aop.ServiceBeanAutoProxyCreator#0' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'serviceAdvice' while setting bean property 'methodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'asyncAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'asyncAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'threadLocalCacheAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'threadLocalCacheAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'bufferedIncrementAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bufferedIncrementAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'indexableAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexableAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'transactionAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'liferayTransactionManager' while setting bean property 'platformTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayTransactionManager' defined in class path resource [META-INF/hibernate-spring.xml]: Cannot resolve reference to bean 'liferayHibernateSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayHibernateSessionFactory' defined in class path resource [META-INF/hibernate-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized(PortalContextLoaderListener.java:172)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
1-updating java connector driver
be sure that the liferay portal is not started ! if it does, then shut down.
download and install MySQL and HeidiSQL, you can simply create mysql database via HeidiSql.
download mysql.jar (Connector/J) from dev.mysql.com
you may not login just go below in page and click link: No thanks, just start my download.
delete mysql.jar in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext
copy mysql-connector-java-some version-bin.jar in
\Program Files(x86)\MySQL\Connector J folder and
paste it in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext .(don't forget to rename it to mysql.jar)
2- work with control panel of liferay
now you can start liferay portal
open in browser localhost:8080/
go to -> control panel -> server administration -> Data Migration
JDBC Driver Class Name:
com.mysql.jdbc.Driver
JDBC URL:
jdbc:mysql://localhost:3306/DB-NAME?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
DB-NAME - name of database you've created earlier.
write MySQL username and password then click the button below.
now in the next page you can see some text in the *red border*like : The system is currently undergoing maintenance. Please try again later.
It's allright. just wait for .. may be half an hour or more or less, just wait, and be patient))
while process is going, you can do the next last step:
3- change portal properties
open file portal-ext.properties (create it if doesn't exist) in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes and paste to this file following text:
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:here must be DB port, by default it's 3306/*DB_NAME*?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=username of MySQL user
jdbc.default.password=password of MySQL user
THAT'S IT
RESTART TOMCAT SERVER
In your portal-ext.properties file, it should be enough if you specif JNDI name to lookup.
jdbc.default.jndi.name=MyDataSource
In your Tomcat's xml file,
<Resource
name="MyDataSource"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8"
username="root"
password="root123"
maxActive="20"
/>
Make sure that the user you are using above (root) has privilege to create the tables.
Also, don't forget to restart your Tomcat container.
Even on top of this if it doesn't work, share the exceptions in your (bin) logs.

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