FluentNHibernate blows up in Windows Service but not website - fluent-nhibernate

I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy.
This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to use NHibernate:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() in C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs:line 28
...more stack trace...
I have checked for an InnerException and there doesn't appear to be one. I have no idea what the PotentialReasons collection is, and Google doesn't seem to be forthcoming either.
This is my dev machine, so when I'm working on my web apps they run locally (i.e. using the web server in Visual Studio). The fact that the Windows Service and my dev web apps are running on this same machine suggest it's not to do with trust settings or what have you.
Can anyone suggest what I should try? This is one of those ones where I'm so stumped I can't even think of how to get more information about the problem.

Just a wild guess. NHibernate picks up the hibernate.cfg.xml file from the execution directory. Did you configure the execution directory of the service that it can find this file?

I've found out what the problem is. The Service did not deploy with the required NHibernate.ByteCode.LinFu.dll.
I appear to have an ongoing problem with the Visual Studio compiler not always copying indirect dependencies (i.e. dlls required by class libraries required by the app) into the output folder during the build. I should have thought of this sooner really.
Thanks for racking your brains on my behalf guys.

I bet the name of the connection string is missing from the app.config. For me that message is almost exclusively a missing connection string.
Are you targeting the same database or could it be some sort of schema mismatch between databases?
Could it be authentication issues on the service like you use windows authentication where it can't be used (or the sql authentication that doesn't work)?
It's hard to tell when there is no code, just an exception!
EDIT Are you ever using HttpContext, HostingEnvironment or anything else specific to "web"?

Related

Anypoint Platform application name missing (flowVars._clientName)

I am facing a weird problem today, when running my MuleSoft application locally from my AnypointStudio and firing a request from postman, I am getting 403 error. When debugging I found out that the application is checking for flowVars._clientName, however it is missing. According to this documentation, actually yes flowVars._clientName is expected.
https://help.mulesoft.com/s/article/How-to-get-the-client-application-name-in-a-flow-based-on-the-client-id-and-client-secret.
So my application fails with 403 error. Seems that other environments are working perfectly fine.
And yes it is using Client Id enforcement.
Any clues?
Without more details it looks like the issue is inside the logic of your application. The KB article that you referenced is a how to in case you need to obtain the client name. It doesn't say that you have to use for authentication. You don't describe how the application does authentication/authorization. Is it in a flow? Or in a policy? If it is the standard Client ID enforcement policy, the expressions to evaluate client id and secret can be configured, but I don't think the default is not #[flowVars._clientName] nor #[flowVars._clientId].
Note that Exchange is basically a repository of APIs and other artifacts. It doesn't authenticate anything at execution time. Unless your application is trying to use it somehow, but I can't think of a reason for that.
The issue was resolved only by re-downloading Anypoint Studio and mule runtime. Very weird, it was happening only for one application, not for the others. Creating a new workspace did not help, deleting the application and re-cloning and installing did not help, even recloning in a new directory did not help. Only using a new Anypoint Studio and runtime installation resolved it (even with the old code base) ...

Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener

While using Windows Azure Table Storage in WCFService WebRole, tried to create CloudStorageAccount by the following way:
storageAccount =
CloudStorageAccount.Parse(Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("[Setting name]"))
Get exception:
ConfigurationErrorsException "Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35."
MSDN help says that 1) Visual Studio must be run as an administrator. 2) A role must be running under full trust (change the .NET trust level option to Full Trust).
All Done, but I still have the same exception.
One thing that can cause this error is running the web role itself, instead of running the containing cloud project. If this is the issue, you could fix it by ensuring that the cloud project is set as the startup project for debugging, and not the web role.
It's possible, and sometimes useful, to run the ASP.NET project that defines the web role on its own. This can be a lot quicker than running things in the Azure Compute Emulator. It may also enable you to develop your project without having to run VS elevated. Also, I've found that the emulator tends to cause Visual Studio to report an invalid memory access error from time to time, at which point you need to restart VS. Running the web role directly avoids all these problems.
However, there are some things that can prevent this from working, and the exception you describe is a symptom of one of these problems. If your web role's Web.config includes configuration for Azure's DiagnosticMonitorTraceListener (and Visual Studio adds that by default when you create a web role) then the first thing that tries to generate trace output will crash with the error you describe if you run outside the emulator. And as it happens, retrieving a setting from the CloudConfigurationManager appears to do this.
This isn't peculiar to the CloudConfigurationManager by the way. All it's doing is producing some trace output. VS configures web roles to send all trace output to the Azure diagnostic listener, and because that listener can only run in either the compute emulator or an actual Azure instance, the first thing that tries to produce trace output will crash. CloudConfigurationManager is a common candidate because it happens to produce trace output, and it typically gets used early on when a role starts up. But in principle, anything that produces trace output could hit this exception.
A simple way to avoid this is to remove the relevant section from the configuration file. When you create a new web role, Visual Studio adds a <system.diagnostics> section that configures the default trace output to go to the Azure diagnostic listener. You could just comment that out. That will enable you to debug the web role directly in Visual Studio without using the compute emulator (assuming you aren't doing anything else that depends on being in a role environment).
Of course, the problem with that is that you'll no longer get any diagnostic traces when running in Azure. One way to solve that is to move the relevant configuration to the Web.config.Release file (adding the necessary xdt: attributes).
This change will also stop the Azure diagnostic trace listener from running when you use the local compute emulator. (That's less of a problem, because the trace messages will still appear in the debugger. It just means you won't get persistent copies of the traces copied to table storage like you would when running for real.) The obvious way to fix this would seem to be to make a similar modification to Web.config.Debug (or to run the release build in the emulator), but there's a snag: apparently cloud projects do not apply configuration file transforms when packaging for the emulator by default. Fortunately, you can fix this: http://blog.hill-it.be/2011/03/07/no-web-config-transformation-in-local-azure/ shows how to enable transforms for local debugging in the compute emulator. (Transforms are never applied when debugging an ASP.NET project directly from within VS, by the way.)
I've found that this error is caused by the wrong version in your web.config
Ie., you may not have
Version=1.0.0.0
Microsoft.WindowsAzure.Diagnostics is up to version 1.8.0.0 as of now
Try updating to the current version
Remove the lines in Web.config < add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener

Publish Biztalk WCF Service with multiple schema files and <includes>

What I have here is this:
A Biztalk project in Visual Studio 2010, a corresponding Biztalk application running on a Biztalk 2010 server. The receive port accepts an HL7-V3 schema, transforms it to a schema that is sent off to a SQL server 2008 instance and inserted into tables via a stored procedure. When the receive port is using the FILE adapter, all works as intended (data from the HL7 file is inserted into tables).
So, we reached the point where a web service was needed in order to expose the Receive port via the web...great we have the "Biztalk WCF Service Publishing Wizard" built right into VS2010. This is where I'm stopped in my tracks.
I can follow the wizard as far as the "Create" step, it makes it about half-way to the Extracting Schemas from Biztalk Assembly then it barfs and throws a generic error:
"The given key was not present in the dictionary"
After much searching and head scratching, I was finally led to fact that the wizard uses Xsd.exe (new to me) to generate code from the schemas. This led me to the MSDN library article Here which states that included schemas are ignored by Xsd.exe. Well, the HL7V3 schema-set for the message we are using has about 30 files altogether - all referencing each other all over the place like so:
<xs:include schemaLocation="../coreschemas/infrastructureRoot.xsd"/>
<xs:include schemaLocation="COCT_MT050002UV07.xsd"/>
<xs:include schemaLocation="COCT_MT090100UV01.xsd"/>
<xs:include schemaLocation="COCT_MT240000UV01.xsd"/>
<xs:include schemaLocation="COCT_MT150000UV02.xsd"/>
So there's my problem.
So now my question is this: Is there a way to manually create a WCF service from a Biztalk project, or better yet, just get the Wizard to work for this case? Or, just any suggestions on where to look, as this is my first Biztalk project.
My Googling has only come up with a plethora of how-to's for the Wizard.
Well, the problem has been solved, despite running down way too many rabbit holes, I stumbled upon an MSDN called Getting Started with HL7 v3 and Biztalk Server 2006 article with a little section called Schema Modifications. One of the modifications is to add Target Namespace to some of the coreschema files in HL7 v3.
I had seen this doc in the past and it mentions that this fixes the issue of them being not supported when compiling schemas in BizTalk Server. I kind of ignored it because I was getting no errors and besides, I was using 2010, not 2006 so I naively thought "that must be fixed now...no errors"
Not so, I did exactly as the document suggested and immediately deployed and ran the Biztalk WCF Service Publishing Wizard and it all worked and I was able to view the help and .wsdl pages that were generated.
I hope this helps someone in the future. Very anti-climactic for me.

WCF service deployed to Azure

I have create a WCF Service Web Role project.I can consume the service locally. But I am having issues trying to deploy the service on the azure cloud. After starting the webrole it justs kepps going in a loop where it init then stops. I have not made any changes to the default WebRoleclass that was added automatically. Can anybody point me to some samples or examples of WCF being deployed to azure
The behaviour you're seeing occurs when the instance errors in the OnStart or Run. The usual diagnostics error trapping hasn't had a chance to start yet so this is a difficult problem to debug. You might try adding error trapping inside this functions that writes the error details out to either a blob or a queue so that you can see what is actually happening.
Having said that, with code that works in the dev fabric, but continues to cycle when deployed to live, the first thing to check is that all of the references have the appropriate "Copy Local" property set. Anything that is part of the framework or Microsoft.WindowsAzure.ServiceRuntime will need to have Copy Local to false, everything else should be set to true (third party assemblies an the like). If this is a web role and you're using MVC, you'll need to check that System.Web.Mvc has Copy Local set to true as well as this is not included as part of the standard framework deployed in Azure.
Have you looked at the Known Issues information on the WCF Azure code page? There's a patch that's needed, as well as a tweak to the service behavior. Hopefully this will help you.
I just found out the root of the problem. It was caused by one of my projects having the target platform set to x86. Seems like it does not support x86 build assemblies which can be a problem

WCF can only serialize parameters on development machine

I have created a WCF service using vb.net. Everything works fine on my development machine but when I deployed it it failed with the following error
'There was an error while trying to deserialize parameter http://tempuri.org/:querys'
I call a single method on the service and it has a single parameter called 'querys'. This parameter was a list(Of CustomType).
I then created a new method with a single parameter of type ArrayList. Thinking that this should serialize. Again it works fine on my development machine but fails when I deploy it with the same error a above.
I am completely stumped how it can serialize a parameter on one machine and not on another. I've tried it on 2 other machine and it doesn't work on either of them. So that rules out a problem with the machine itself.
All machines are running Win XP and .Net v3.5. The service was developed using VB .net in Visual Studio 2008.
Has anyone else experienced this?
I have not included any code because the error is happening System.ServiceModel and as I mentioned above the code does work on the development machine.
Please let me know if you need any more information.
Thanks in advance
Did you mark your 'CustomType' and its fields/properties you want to serialize with attribute DataContract, DataMember?
When you add the service reference to your client app which setting do you use? (Reuse types in referenced assemblies, always generate message contracts...)
If you host the WCF service on a IIS, then you should remember to run this command on the servers.
C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe /i /x
Thanks to everyone who replied,
I have resolved the problem but unfortunately do not how. I tried many code changes but as far as I can tell I have reset the code back to the way it was. It is working now and I can not spend any more time on the issue to find out what caused it.
Just one of those things I guess.