enable-migrations Object reference not set to an instance of an object - ef-code-first

I have a problem adding a new migration to an already migrations enabled project.
Adding previous ones worked.
As I conceptually refined my model, I reflected those changes to my already mapped classes.
When adding a new migration I received this error :
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.Entity.Migrations.MigrationsDomainCommand.WriteLine(String message)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.

Related

Resolution failed with error: No public constructor is available

I am using WCF web services and it was using OLD unity 2.0. So i updated Unity and other reference with latest version 5.0. I am getting exception:
Resolution failed with error: No public constructor is available for type xyz.Services.Contracts.Security.IAuthenticationService.
For more detailed information run Unity in debug mode: new UnityContainer().AddExtension(new Diagnostic())
Exception of type 'Unity.Exceptions.InvalidRegistrationException' was thrown.
Really i tried many things but not success. please any expert have a look.
I came across the same error upgrading from Unity version 3.5 to 5.11. In my case, during resolution the exception was the same ResolutionFailedException with message "No public constructor is available for IMyInterface" and having the same inner exception InvalidRegistrationException.
Well, the error messages and types of exceptions were misleading in my case; there was no registration problem nor did I ask for a public constructor for the interface. It seems that there has been a breaking change in the Resolve method overload which takes an instance name. Null names are no longer equivalent to empty string names. Replace your empty string name to null or use the other overload which doesn't specify an instance name:
var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>();
OR
var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>(null);

Facing Error During Tibco AMX Deployment : "AMX Invalid boolean value 'False'"

When Deploying an Application I am facing issues. After looking at the node logs I found this Error:
"org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid boolean value 'False'
How can I resolve this?
When looking into the substitution Variables in Tibco admin and Property file I realize there were two Boolean SV defined. I had to remove it from our script and deploy the application. The application deployed just fine. Later on I went into admin and changed the default Boolean values to desired values.
Alternatively, Try SV Boolean values in the lower letters.

Unity resolving unmapped types with null

If I don't have the concrete class mapped to the interface, when Unity tries to resolve the type it gives me this error: "The current type, IFoo, is an interface and cannot be constructed. Are you missing a type mapping?".
However, for testing purposes, I'd like Unity to pass null to the interfaces that aren't mapped yet to concrete types.
Any suggestion to make this as the default behavior to "resolve" unmapped interfaces?
Thanks
I could let Unity pass null to my dependencies using the OptionalParameter while configuring the constructor injection.
container.RegisterType<IObject, MyObject>(
new InjectionConstructor(
new OptionalParameter<IFoo>()
)
);

Inner SecurityException while using XmlSerializer

While creating a custom Sharepoint web service I received an error while attempting to serialise a class for transmission.
There are no errors with my serializable classes. They are structured in a manner I have used before and can be serialised successfully on a local test environment, the issue only arises when the Sharepoint web service has been deployed.
System.InvalidOperationException was caught
Message=There was an error generating the XML document.
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at SPServiceExtensions.DTOSerializerHelper.SerializeDTO(SharepointDTO dto)
InnerException: System.Security.SecurityException
Message=Request failed.
Source=xo46jp-i
StackTrace:
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSharepointDTO.Write4_SharepointDTO(String n, String ns, SharepointDTO o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSharepointDTO.Write5_SharepointDTO(Object o)
InnerException:
The inner SecurityException was unfamiliar. What is causing this Exception?
ASP.NET uses different trust levels for it's security policies. This is so applications cannot access the data from other unrelated applications.
Microsoft Sharepoint has two additional code access levels of its own and by default runs on WSS_Minimal.
As the webservice is operating as a local application on the Sharepoint server it requires Full Trust
However Microsoft discourages applying full trust willy nilly. I gather that it potentially allows other applications to call your code which has the potential of being used maliciously to exploit the system.
So a better way to prevent the SecurityException is to modify the projects AssemblyInfo.cs and add this attribute [assembly:AllowPartiallyTrustedCallers] to it.
Microsoft's article on Code Access Security.

A one time error breaks subsequent usage of Entity framework

We have a problem with entity framework. For example if we do:
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
and then we try to delete an entity that has mapped child entities who depend on it, it is logical that we get an error. (Cannot delete parent when there are children in database that depend on it).
Afterwards, using a new context instance, doing a 'ParentEntity.ChildEntities.ToList()' there is still a problem!
A workaround is to restart the app pool, and the problem goes away.
We are using Autofac and the lifecycle of the context is set (and confirmed) to per HttpRequest, so the error persists somewhere else. Any idea what can be done so as to avoid these errors?
Our guess is that the objectcontext is persistent somewhere else, and it stores the state of the child entities as "EntityState.Deleted" so this conflicts with the actual data received from the database on subsequent calls.
Update: Seems like a closer examination of the stack reveals that there is a lazy internal context:
[DbUpdateException: An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details.]
System.Data.Entity.Internal.InternalContext.SaveChanges() +200
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +33
System.Data.Entity.DbContext.SaveChanges() +20
Maybe if I were to somehow disable LazyInternalContext? Can this be done?
If you don't want to get the exceptions and keep the database in a valid state by your self for some reason you can do so by stopping validation:
context.Configuration.ValidateOnSaveEnabled = false; // you can put this in the constructor of your context;
context.SaveChanges();

Resources