Adding reference which is needed in Config file - c#-4.0

I have two different projects 'A' and 'B'.A needs reference of B.I used spring.net setter property injection.I configured it in config file.
I have one more new console application where i added only 'A's reference and im getting the 'A's instance through XmlApplicationConext(path).but after running it im getting object creation exception.
Do i need to add 'B's refrence also in console application.if yes then what is the use of using spring .net config file.
Does Spring.Net internally automatically will load the dlls required.

Spring will automatically load the required dll's. As far as I know, it will look for the dll's to load in the same order as any other .NET application.
If you configure the console application to use classes from project B, then B.dll (the output dll from project B) has to be available to the console application at runtime only. You do not have to add a reference to project B to achieve this; you could also copy the B.dll file to the output directory.
I'm not sure what you mean by "the Spring.net config file", but be aware that config files are not automatically loaded, you have to specify them explicitly. You can import another configuration file in you configuration file, see the docs for a how-to:
<objects xmlns="http://www.springframework.net">
<import resource="file:///services.xml"/>
<import resource="assembly://ProjectB/MyDataAccess/data-access.xml"/>
<object id="object1" type="..."/>
<object id="object2" type="..."/>
</objects>

Related

Include referenced assembly's configuration in cspkg

I have an executable that I want to be deployed together with my Azure web role. The executable has a configuration file that needs to be included as well.
I tried adding a reference to the executable's project in my web role project, which made the exe file appear in the bin folder of the cspkg, but not the configuration file.
How can I get the configuration file to be included as well?
It seems wrong to include it directly as a content file in the web role project because this file is a build artifact (app.config gets renamed to .config.exe during build).
Thanks!
In an early SDK they added the concept of Role Content folders, or folders you could point to in the service definition file and say anything in this folder, add it to the package and deploy it with the role. If you look at the schema for the Service Definition you'll see these listed on the both the web and worker roles schemas. You can manually add this and point to any location on the local system and anything in that directory will be picked up and included.
<WebRole name="SimpleWeb" vmsize="Small">
...
<Contents>
<Content destination="ConsoleApp">
<SourceDirectory path="c:\src\SimpleWebContent\ConsoleApp\BuildOutput" />
</Content>
</Contents>
</WebRole>
For example, you could point to the output directory of the build for your executable so that anything that is generated by your build for that executable would be included. You can set the destination directory in relation to the app root, but the tricky part is the source directory. Note in my example above the full path is provided. The documentation says that you can use a relative path, but I tried many combinations and the behavior seemed very quirky. The complete path does work.
The VS SDK tools didn't expose this until SDK 1.7 and it's still not very good. Phil Hoff did a blog post on it called "Add Files to your Windows Azure Package using Role Content Folders". Note that when you use this method of adding the files you won't see the content elements appear in your service definition. They get auto injected at package time. If you are doing this as part of a build process that may not happen since VS tooling is doing the injection, but to be fair I didn't try calling cspack directly to see if having the content elements included in the service definition file actually packaged those or not. Also, I found that just adding a new folder and just having files under that folder didn't seem to work. I had to actually add the files by name there, which seemed wrong. I did hack the .ccproj file to use a wildcard on the folder include, which did work, but also seemed like a hack to me.

What is the name of the web role .config file with SDK 2.2

I have a web role in which I have extended the RoleEntryPoint to do some work that is outside of the scope of the web site. As part of the RoleEntryPoint.Run() my code is required to read from the .config using ConfigurationManager.
While this is a little unusual, using SDK 1.8 I was able to make this work by ensuring that my package included a [The name of my project].dll.config file.
Now that I have upgraded to SDK 2.2 when I try to use .AppSettings or .GetSection() the values are always null, which leads me to believe it is unable to find my file.
I have tried deploying a Worker Role and the .config file still follows the same name pattern that I'm currently using.
I have also tried naming the file WaIISHost.exe.config.
I am aware that ideally this configuration should be included in the .csfg file, but my questions is does anyone know what I should be calling my config file?
UPDATE:
With the help of this question, I now know that the name of the config file it is reading from is E:\base\x64\WaIISHost.exe.Config, but I don't know why this has changed or what I can to overide this.
After much investigation and trial an error I finally have a solution.
The name of the file is still required to be [The name of my project].dll.config, but you need to make sure that this file is in your approot\bin\ directory of your package.
I believe my initial problem was caused by the Copy to Output Directory property being changed to Do Not Copy, although I'm unsure how this happened. If you find yourself in a similar situation you can just add a file with the correct name to your project and set the Copy to Output Directory to be Copy Always.
Once I'd done that however I realised I had another problem. I needed the .config file to have had the config transformations run over it, which this didn't do. To fix this I updated the .ccproj file to have the following:
<PropertyGroup>
<!-- The first two of these targets are what is defined in the base SDK 2.2 targets file. When we upgrade we may need to look reassess this. -->
<CopyRoleFilesDependsOn>
CopyWebRoleFiles;
CopyWorkerRoleFiles;
CopyWebConfigToBin;
</CopyRoleFilesDependsOn>
</PropertyGroup>
<Target Name="CopyWebConfigToBin">
<!-- We need to copy the transformed Web.config to the bin directory so that the RoleEntryPoint has access to the config settings.-->
<Message Text="Copy %(WebRoleReferences.OutputDir)Web.config tp %(WebRoleReferences.OutputDir)\bin\BackOffice.UI.dll.config" Importance="high" />
<Copy SourceFiles="%(WebRoleReferences.OutputDir)Web.config" DestinationFiles="%(WebRoleReferences.OutputDir)bin\[Name of project].dll.config" />
</Target>
This adds an extra target which waits until all of the other files have been copied to the appropriate directory and then picks up the web.config and puts a copy in the bin directory with the correct name.
Are you able to put the config values into the Azure config file (the .cscfg) rather than using the .config file? You can read the values from the cscfg via the RoleEnvironment.GetConfigurationSettingValue static method.
This page explained why it's called WaIISHost.exe.Config and where you can put it in your project.
http://azure.microsoft.com/blog/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core/
Like knightpfhor mentioned, you can also use [AssemblyName].dll.config to put these configuration too. It depends on the assembly name of your project, you can check property of your web role project.

WS02 ESB - How to get Custom java class property file on the classpath

I have loaded a custom jar file into WSO2 by placing it into the /repository/components/lib directory, performing a restart. I then call that class from a script mediator using inline groovy. The groovy script recognizes the class, however the custom class is attempting to load a properties file that must be on the classpath. I have put that property file nearly everywhere but I keep getting an error that it cannot find the file on the classpath.
I am running the standalone WSO2 ESB 4.7.0. I have put the file as part of the jar, I have also attempted to place it in several directories within the WSO2 file structure as well. All to to avail.
you could try to register a resource in the carbon registry and add a Property to this Resource. Basically there are two ways (in java...):
Here is an example how to connect to the registry via a service with the PropertiesAdminServiceStub: http://www.massapi.com/class/org/wso2/carbon/registry/properties/stub/PropertiesAdminServiceStub.java.html
The most important here is that you authenticated your user, the result is a cookie which yoou have to add to the stub.
The other would be something like this (probably a duplicate of your question)
I am unable to get the list of services with in the applicaton i.e.; wso2 governance registry? I am working with binary code
The last one asumes that the carbon-context is available, means you are running the search inside the wso2 like a feature for example.
Unfortunately there is no place to put that properties file. Luckily this jar file, is an in house entity. It was written to search the classpath for the properties file and upon not finding one on the classpath to throw an exception. We ended up rewriting the code that loads the properties file to upon not finding the file on the classpath to search in a directory which we specified as a system environment variable in the wso2server.sh file. Not very elegant, but it is working perfectly.

how to set log4j.configuration system variable in WebSphere 7?

I have a Java EE 5 web app I'm deploying to WebSphere 7 as an EAR file.
I want my log4j configuration to be external to the EAR file so I can tweak log content when needed without needing to rebuild and redeploy the EAR file.
My understanding is I can specify the location of my log4j.properties file by setting a
"system variable" called log4j.configuration. (ex. log4j.configuration=c:/log4j.properties)
My question is, how do I set this system variable in the WebSphere 7 admin console?
Browsing around I see there is Environment > WebSphere Variables, but that doesn't look right because that would be setting a variable for the entire server. I'm guessing I want to set a system variable just for my application EAR file.
Any help or suggestions is greatly appreciated!
Rob
The log4j.configuration property is a Java Virtual Machine system property. You can load this property by adding it to the end of your application server's list of generic JVM arguments. This is done in the WebSphere Console by navigating through the following:
Servers > Application servers > [app server name] > Process definition > Java Virtual Machine
Under Generic JVM arguments, add the following:
-Dlog4j.configuration=file:C:/log4j.properties
Click Apply at the bottom of this page, and save your changes. This will require a restart of the application server to take effect.
You can also use shared library for an application and put your log4j.xml there.
I find a solution to assign to each EAR or WAR an external log4j.xml configuration file:
I extracted the log4j.xml from our EAR, Zipped this lone XML into a JAR file. Placed it on the server in a path accessible by WebSphere,
Create a Shared Library (WebSphere > Environment > Shared Libraries) mapping the classpath to this archive. Make sure to select "Use an isolated class loader for this shared library" or you'd have to assign reference for each module of your application rather than just the parent EAR.
Assigning the reference within our EAR
(Application -> ApplicationType -> WebSphere enterprise applications -> EAR NAME -> Shared library references -> SELECT YOUR EAR -> Reference shared libraries -> SELECT THE LOG4J CONFIGURATION JAR) and ADD IT.
Restart the application
I used this way to assign a specific external log4j configuration file to each WAR in an an EAR.
Here you can find the original solution.
How to point Log4j.xml(not log4j2.xml) to external file
For Log4J (not Log4J2) in websphere 8.5 in Linux OS, please a custom properties under Servers > Application servers > [app server name] > Process definition > Java Virtual Machine.
property name: log4j.configuration property value : file:/xyz/abc/def/config/log4j.xml
NB: You don't need to append -D if you do it from custom properties. But if you give it under Generic JVM arguments use this:
-Dlog4j.configuration=file:/xyz/abc/def/config/log4j.xml -Dlog4j.debug
Each property must be separated by space. I added debug logs for Log4J itself to see from where it is picking the log4J.xml file.

Using SubSonic Active Record in a seperate assembly from the Web

I'm following the tutorial here.
I created a new Web Application. I then added two Class Library projects, Common and Domain. The common project contains the SubSonic library while the Domain project contains the SubSonic .tt and .ttinclude files.
After modifying the settings in Settings.ttinclude, I try to 'Run custom tool' on the tt files and I get this error:
Running transformation: System.ArgumentNullException: Value cannot be null.
Parameter name: The project does not contain App.config or Web.config file.
I can provide the rest of the stack trace, but it appears that it can't find my Web.config which was the connection string. Adding an app.config to the Domain project just causes the generation step to complain about not finding expected sections.
Is there a way to have these files in a separate assembly but still use the web.config for settings?
You need to place an App.config in the project you want to generate from. Yes, it's redundant but there's no other way to handle this with T4

Resources