Does App.config (or ApplicationName.exe.config) work in mono? - mono

I'm trying to get EntityFramework 6 with dotConnect for Oracle working on Mono.
I have also all app configuration defined in userSettings section.
First thing I noticed is that my app has always default configuration, then I tried to make Devart.Data.Oracle provider working, but I got an error:
System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'Devart.Data.Oracle'.
I checked my app with strace and using MONO_LOG_LEVEL:
MONO_LOG_LEVEL=debug mono Host.exe | grep config
And config file is loaded (successfully) couple of times during app startup.
I found few bug reports about configuration in mono, but they are quite old and I don't know if still actual.
https://bugzilla.xamarin.com/buglist.cgi?quicksearch=ApplicationSettingsBase+
Could you give me a hint how to get rid of provider section in App.config?
I've managed to move almost all configuration to code (except of providers).

First, your exception is not about wrong configuration. It loaded and read your configuration, but then it cannot find provider (Devart.Data.Oracle) specified in that configuration. Most obvious reason for that is missing dll which contains that provider.
Second, this is how I use EF6 + Devart's postgresql provider (you use Oracle, but that should be similar) on mono without any configuration files:
public class PgSqlConfiguration : System.Data.Entity.DbConfiguration
{
public PgSqlConfiguration()
{
SetProviderServices("Devart.Data.PostgreSql", PgSqlEntityProviderServices.Instance);
SetProviderFactory("Devart.Data.PostgreSql", PgSqlProviderFactory.Instance);
}
}
Then mark your context with DbConfigurationType attribute like this:
[DbConfigurationType(typeof(PgSqlConfiguration))]
public partial class YourContext : DbContext {}
Just replace PostgreSql providers with Oracle in code above (and don't forget to add missing dll if that is the case) and you should be fine.

Related

IIS looking at wrong path for MVC configuration file

When I run MVC4 my application using Visual Studio Development Server, my application is able to load all configuration files correctly. But when I try to run it under the Local IIS Web server, it throws this error
{"Could not find a part of the path 'C:\\Windows\\SysWOW64\\inetsrv\\~\\nhibernate.config'."}
It's looking at the wrong folder. The config file is directly in the root of my web project. Why is this happening. How can I fix it. I'm pretty sure that nhibernate looks for this file in order to load it's properties. Unless you know how to move nhibernate configuration files into the web.config file, please don't recommend that, I get a "Unrecognized configuration section hibernate-configuration" when ever I copy it over
Edit:
by the way, I'm pretty sure it's looking at the following key in appSettings my app settings section
<add key="nhibernate.config" value="~/nhibernate.config" />
Edit2:
here is the stack trace that goes into how Nhibernate is getting this value, and trying to find the configuration file
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure(String fileName)
at AndroMDA.NHibernateSupport.DefaultSessionManager.BuildSessionFactory()
So it wasn't actually NHibernate that was using this file. My boss decided to use something called AndroMDA to generate code, and part of that generation was some NHibernate Support that I couldn't see into.
If anybody is interested, I created a new implementation of ISessionManager, which looks exactly like DefaultSessionManager except for the following member function and variable.
public class ServerMapSessionManager : ISessionManager
{
//other interface implementation...//
public static HttpServerUtility Server { get; set; }
public String TranslateConfigPath(String virtualPath)
{
return Server.MapPath("/"+virtualPath);
}
}
Then in App_start I call the following
SessionManagerFactory.SessionManager = new MVCFramework.Core.Common.ServerMapSessionManager();
MVCFramework.Core.Common.ServerMapSessionManager.Server = Server;

Add Service Reference doesn't generate proxy

I understand there are other similar questions, but I haven't been able to find a working response.
I create the default WCF service from the template [which comes with GetData() and GetDataUsingDataContract()].
It runs fine in the browser.
I have a separate web site to which I add this new WCF service:
I do 'Add Service Reference', enter my URL, the service comes up and I click 'OK' to add it.
Under 'App_WebReferences', I see the namespace of my added service: 'ServiceReference1', with 'References.svcmap' under it, and a couple .svcinfo/.wsdl/.xsd files under that.
No proxy files are created, but <system.serviceModel> element is added to my web.config, with what seems to be proper information.
However, with no proxy, I can't access/call any methods in my service (ie ServiceReference1.WCFMethod1())
I can call svcutil, generate the proxy, add it to my App_Code, and everything works as it should.
My question is, why isn't my proxy being created with 'Add Service Reference'?
Everything is under target framework: .NET Framework 4.
EDIT:
Just created a Console App and added the service reference and it created the proxy.
So the issue is my web site is not creating the proxy...
I had this same problem and found that unchecking Reuse types in all referenced assemblies did solve the problem. However, in my case, I needed it to reuse types from some of my referenced libraries. I found this post, covering a very similar problem. In that post, it references a Microsoft knowledge-base article which describes a fix for the the following issue:
Consider the following scenario:
You create an ASP.NET MVC4 Web API project in Visual Studio 2012.
You add a WCF service reference in the project.
In this scenario, the Reference.cs file for the service reference is empty.
Cause
This issue occurs because the DataContractSerializer class has encountered a type (Newtonsoft.Json.Linq.JToken) that it does not support. In this case, it throws an exception, and then stops generating the service reference.
I wasn't referencing that JSON library, but, based on that bug description, I surmised that one of my referenced libraries must have had a similar problem. I figured that one of the libraries that I was referencing probably contained a type that was not supported by the DataContractSerializer, it was throwing the same kind of exception, and it was therefore failing in the same way.
Sure enough, I found out that, in my case, the culprit was one of my own libraries which happened to include a public proxy for the same WCF service. I suspect it was that public proxy that was causing the trouble. In any case, by selecting Reuse types in specified referenced assemblies, and then selecting all of the assemblies except that one, the service reference automatically generated the proxy classes correctly.
When you are adding a ServiceReference : References -> Add new service reference.
Clik on advanced button and uncheck "Reuse types in all referenced assemblies".
This option sometimes causing errors.
Here is the main issue.
The issue source is when you are not able to find Add Web Reference in your visual studio. If the service is asmx, in my case it wasn't generating proxy class until I found these steps -> click on Sercice Reference -> Click on Advanced -> There you will see Add Web Reference... Provide your service URL hit OK issue resolved.
Hope this helps.

Error 404 - file not found on Silverlight RIA service call

I have search everywhere for a solution to my problem, but I am not able to find one. I have built a Silverlight 4 Navigation app, and am using RIA Services to process a custom entity (which is essentially running server-side calls to COM dlls). In my debug environment, everything works fine, but when I try to deploy to IIS7 (on the development machine) as a website, it gives me the following error when calling the Get query on the entity:
Load operation failed for query 'GetNewHWCoil'. The remote server returned an error: NotFound.
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Everything I found online says to check the Authentication area on IIS and make sure that it is set only to Anonymous Authentication, which it is. And they also say to enable WCF logging, which when I add the necessary text to the web.config file, I still don't get any logs. They also say to use Fiddler2 to trace the HTTP calls, but I only get a 404 error on there with the textview giving me the standard IIS file not found website. I cannot figure out how to debug this problem.
The Silverlight app needs to make calls to a set of 3rd party COM dlls to calculate the performace of water coils. Since I do not want to have the app run OOB, (this will negate the whole point of it being a web app instead of a WPF app) I have the ASP.net project interacting with the dlls using the custom entities.
The function (or Query as RIA services calls it) GetNewHWCoil is located in the DomainService class and uses this code:
Public Function GetNewHWCoil() as HWCoil 'HWCoil is a custom object
If bRanCalc then 'bRanCalc is a global boolean variable that gets set to true if the calc call on the dlls have been made
Return mHWCoil 'global copy of the calculated coil object
bRanCalc = False
else
Return New HWCoil
end if
End Function
The error runs before any calculation should be called, so it is assumed that it is erroring on the 'Return New HWCoil' part.
Any help on this would be appreciated.
Thanks,
Chris
I found the solution to my problem. I fonud out that I can have VS run the debug from IIS, and when I had it create the virtual directory it told me I needed to install ASP.NET 4 on the server. I thought that by checking the ASP.NET checkbox in the Add Windows Features dialog that I had already done that. But it only installed .NET 2 version. So after looking online for this new problem, I found that I needed to run the command
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i
and everything worked fine after that.
Chris

FluentNHibernate blows up in Windows Service but not website

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"?

Servlet Exception + Class Cast Exception + Glassfish + Netbeans + JPA Entities + Vaadin

I get this error:
StandardWrapperValve[Vaadin Servlet]: PWC1406: Servlet.service() for servlet Vaadin Servlet threw exception
java.lang.ClassCastException: com.delhi.entities.Category cannot be cast to com.delhi.entities.Category
when I try to run my webapps on glassfish v2.
Category is a JPA entity object
the offending code according to the server log is:
for (Category c : categories) {
mymethod();
}
categories is derived from:
List<Category> categories = q.getResultList();
Any idea what went wrong?
This is a class loader issue. If a class is loaded by different class loaders, it's objects cannot be assigned to each other. You have probably passed an object from one WAR into another one. There are several options to resolve this:
Put all your code into a single WAR.
Use some form of remoting between your WARs. Serialization takes care of the class loader problem.
Try putting all you WARs into a single EAR. If that doesn't work, put all code into JARs that are on the EAR's Classpath in the MANIFEST.MF.
I once had the same problem and the environment I had was following:
I had Glassfish v4
Netbeans with following projects
webpage war project containing entities
and ear project with that webpage war project
The problem was that in war's project settings I had checked [x] Run>Deploy on save. This was causing deploying war project everyime I hit save. It was sometimes leading to PermGen (memory) problems and unability to deploy EAR correctly (because e.g. in between undeploying and deploying EAR - this "crazy" Netbeans was deploying this war).
Solution: If Netbeans && using EAR, then uncheck deploy on save in project properties.
EDIT:
it seems that this error is connected with
SEVERE: The web application [/faces] created a ThreadLocal with key of type [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1] (value [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1#249ea63a]) and a value of type [org.glassfish.web.loader.WebappClassLoader] (value [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
I've had same problem today. Solution was closing EntityManagerFactory after use.
This answer helped me:
https://stackoverflow.com/a/13823219/2455506
I'm experiencing this problem too with Glassfish v2 and Glassfish v3.
Can I ask you a question: Are you attempting to initialize any persistence object when the application is deployed (through a servlet loaded on startup or a context listener)?
Like bguiz, I've noticed this problem only happens on redeploy. A new deploy to a freshly restarted Glassfish server, never has this problem.
Like FelixM mentioned, I'm convinced this is a class loader issue, however I don't believe it's an issue with multiple wars (I only have 1 deployed to my server). In Glassfish 3, I can see that my WAR is utilizing 2 Glassfish "engines". One for the web(war) and one for the jpa. From what I understand, these are different containers each with their own classloader. I'm guessing Glassfish v2 works in the same manner.
I'm using Spring and (re)initialize some persistence objects on (re)deploy. What I'm thinking, is that while the web engine is reinitializing the war, the jpa engine is still using the old class definitions. Often if I retry the redeploy after this initial failure, it may succeed (sometimes it may take more than one retry but eventually I can get it to succeed without a restart - having better success with Glassfish v3 than v2).
At this point I'm thinking that either these two classloaders are out of sync or there is some sort of race condition on redeploy allowing this operation to sometimes succeed. I've tried to force the classloader, writing code like this
HashMap<Object, Object> properties = new HashMap<Object, Object>();
properties.put(PersistenceUnitProperties.CLASSLOADER, this.getClass().getClassLoader());
entityManagerFactory = Persistence.createEntityManagerFactory(jpaContext, properties);
but it didn't seem to have any affect.
I'm also wondering if eliminating the initialization at startup could fix the problem, giving the appserver time to resynchronize both engines before using any jpa classes (which is why I asked my follow up question).
My observation is that it only happens when using a hot redeploy or a static redeploy. This only applies, of course, if you get a class cast exception where both the to and from classes are the same.
Workarounds:
Don't use undeploy and deploy instead of redeploy
Restart app server
Remove static members of the affected classes
Use a remote interface (serialization makes this go away)
IMO I think the class loader was unable to reload the class and the old version was reused, resulting in the error.
This article doesn't talk about this error directly, but it is good background info on how the class loader works.