Problem with spring + nhibernate in .net environment - nhibernate

I am working with Spring.net 1.3 and nHibernate for .net 1.3.
While fetching the application context using XML ( _appContext = new XmlApplicationContext("abc.xml")) I am getting the exception as
"Error creating object with name 'NHibernateSessionFactory' defined in abc.xml"
Initialization of object failed : The following types may not be used as proxies"
I have declared all the properties of class as public virtual.still why am i getting this exception
Thanks in advance

You must have missed marking a property or method virtual. The exception (or an InnerException, I'm not familiar with Spring) message should tell you exactly which type is the problem. For example, I just reproduced this:
{"The following types may not be used as proxies:\nModel.Project: method get_ProjectId should be 'public/protected virtual' or 'protected internal virtual'"}

Related

Is it possible in ASP.NET Core to enable XmlSerialization for a single controller

I have a Web API that has several controllers, one of which returns XML for legacy reasons, while all the others return JSON.
In a .NET Framework I can selectively enable XML serialization for a single controller by accessing HttpControllerSettings.Formatters (typically in an attribute used to decorate the controller).
Is it possible to do the same in ASP.NET Core, i.e. only enable Xml serialization for a single controller?
The only way I've found to enable Xml serialization in ASP.NET Core 2.1 is globally, using:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddXmlSerializerFormatters();
This works OK, but has a side-effect that I consider to be undesirable: when I run the application in Visual Studio I see a trace of an warning from XmlSerializerOutputFormatter something like:
Microsoft.AspNetCore.Mvc.Formatters.XmlSerializerOutputFormatter:Warning: An error occurred while trying to create an XmlSerializer for the type 'MyApp.MyModel'.
System.InvalidOperationException: There was an error reflecting type 'MyApp.MyModel'. ---> System.InvalidOperationException: Cannot serialize member ... see inner exception for more details. ---> System.NotSupportedException: Cannot serialize ... because it is an interface.
--- End of inner exception stack trace ---
at System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type)
...
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at Microsoft.AspNetCore.Mvc.Formatters.XmlSerializerOutputFormatter.CreateSerializer(Type type)
It appears to be trying to create an XmlSerializer for a Type that is not used by my "XML" controller.
While it's not a showstopper, I'd prefer not to be creating XmlSerializers except when I need them.
I've encountered the same issue. I do not believe there is a solution at the moment, so I've created a feature request on the Github project.
In the meantime, I've set
"Logging": {
"LogLevel": {
"Microsoft.AspNetCore.Mvc.Formatters.XmlSerializerOutputFormatter": "Error"
}
}
To suppress the warnings during startup.
I've encountered the same issue.Then I changed my code:
builder.Services.AddControllers().AddNewtonsoftJson().AddXmlSerializerFormatters();
U can check this one out, I hope it's has been helpful.

In ServiceMatrix, is it possible to 'ConvertToSaga' an endpoint which publishes/subscribes event messages rather than command messages?

I've got a solution with 4 NSB host endpoints which were created using ServiceMatrix and I want to use them within a saga.
I know how to Convert To Saga from a command and that works fine in a test project. What I don't understand is how I can do the same thing with published events, as the menu option is not available. Is it possible to do this using ServiceMatrix ?
I have tried to implement the changes by hand by following this tutorial and observing the changes that were made to my test project when I Converted To Saga.
It builds ok but throws an error within the framework when running:
System.InvalidOperationException was unhandled
Message: An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: No IBus instance available, please configure one and also verify that you're not defining your own Bus property in your saga since that hides the one in the base class
I'm using VS2013 and ServiceBus 5.
UPDATE:
I commented out the inherited IHandleMessages<> interface and public IBus Bus property from the generated code and it runs without this error. I'm not happy doing this, as the next design change using the tool will overwrite these fixes.
In your command handler you usually have a property of type IBus that is injected to the handler class either by property injection or constructor injection.
When you move from a command handler to a Saga, you need to remove your IBus property from the handler. Saga base class has a Bus property that you should use instead. This property is populated for you automatically, you should not care about this. This is exactly what this exception is telling you.

NServiceBus.ObjectBuilder.Ninject critical bug

I'm experiencing this error mentioned on the nsb group when running in the NServiceBus.Production profile.
Just wondering if it's a known issue (Remo ? :-) ) because it's currently going to prevent me using ninject with nsb.
NServiceBus.Ninject-CI.3.0.2044 nuget.
Many thanks!
2012-02-28 15:24:18,204 [Worker.8] WARN NServiceBus.Unicast.Transport.Transacti
onal.TransactionalTransport [(null)] <(null)> - Failed raising 'transport messag
e received' event for message with ID=02e57b0c-f345-46ae-a095-f52a4cfc0cfb\2071
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
at Ninject.Injection.DynamicMethodInjectorFactory.EmitMethodCall(ILGenerator
il, MethodInfo method) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\Injection\DynamicMethodInjectorFactory.cs:line 130
I didn't write the NSB ObjectBuilder for Ninject. From the exception I can tell that Ninject fails to inject a property because there is no public setter. With the an unchanged Ninject this cannot happen because these properties are filtered before unless Ninject is explicitly told that it shall not filter none public members.
I had a short look at the NinjectObjectBuilder. It adds new heuristic and it seems that it does not filter public properties with private setters. This implementation requires some change.
But I think this won't fix your problem since you want to have that property injected anyway. The proper way to do so is to change the setter to public. Alternatively, you can change the settings to allow privat member injection. Settings.InjectNonPublic = true; But I don't recommend to do that.

WCF service reference stopped generating code for one project

I have references to two different WCF services in a project. I updated the reference for one of the services, and now no code is generated for it. The references.cs file just has the "this is genrated code" comment at the top. Updating that same service in other projects and updating the other service both work fine. It's only that one service reference in this one project that's causing the problem, and I'm getting no information from Visual Studio (it just says it failed to generate code and I should look at the other errors, which provide no information).
If I uncheck the "reuse types in referenced assemblies", code is generated, but I don't want to have this one project be different from the others. I'd like to solve the problem. Re-checking the reuse type option produces an empty references.cs file, again. The collection type doesn't seem to matter, either.
How can I diagnose and solve this problem?
Update:
It seems I was mistaken. Updating the service reference does seem to break the generation in other projects as well. I did also notice these warnings, as well:
Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: ISerializable type with data contract name 'Exception' in namespace 'http://schemas.datacontract.org/2004/07/System' cannot be imported. The data contract namespace cannot be customized for ISerializable types and the generated namespace 'TheDefaultNamespaceOfTheProject.ServiceReferenceName' does not match the required CLR namespace 'System'. Check if the required namespace has been mapped to a different data contract namespace and consider mapping it explicitly using the namespaces collection.
Obviously I changed the namespace there, but it seems like it's trying to map System.Exception to ThatNamespace.Exception? Why would it do that, and how can I correct it? I think this is the key to the whole thing.
I had a similar error in a Silverlight application making WCF calls. I created a WCF method that passed an Exception object as a parameter. It turns out that Exception objects are not serializable in Silverlight because:
http://blogs.msdn.com/b/suwatch/archive/2009/01/21/wcf-silverlight-exception-and-serialization.aspx
Here's the relevant excerpt:
WCF’s DataContractSerializer serialize s Exception class via
ISerializable (Exception in .Net Framework implements ISerializable).
However, in Silverlight, there is no ISerializable interface.
Therefore, Serialization information of Exception transferred over the
wire will not be set into the Exception class. This does not only
apply to Exception but also any types implementing ISerializable on
the .Net Framework serialized to Silverlight.

Interface type as property of class throws error on client WCF

Hi I have a class which has a property of type of an interface
public class A
{
public List<IInterface> interface {get;set;}
}
Public class B : IInterface
{
// Some properties
}
A wcf service is calling a OpertaionContract which return an object type of this object but it fails on my client.
I had already added the ServiceKnowType attribute on all implemented classes on the service contract but still i am getting the same error
"Consider using a DataContractResolver or add the type corresponding to 'B' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer
I am really confused how this would work , please advise thanks.
I added the KnowTypeAttribute at the right datacontract so the above error went away but now I am getting a generic error of underline connection got closed.
Updated:This link helped me out in resolving the Interface issue How can I pass a List<Interface> over WCF?
But right now enums are giving me a similar issue my object breaks on client cause of enums properties being defined in the class.
for your enum problem, are you using EnumMember for the enums? See http://www.codekeep.net/snippets/0002f271-1418-4027-b19a-3820702fc22f.aspx for an example.
If that doesn't solve it, can you share the error message you're getting with the enum usage?