I've got two projects, WebAPI project as A and MVC4 project as B.
The dll of A project is referenced in B project.
I found that A's dll is using the config setting in B's web.config.
These projects have different definition for corresponding web.config.
So how can I do A's dll to use its own web.config and not to use B's web.config?
The configuration file is read only from starter project. You can merge configs if they differ in appsettings or connectionstrings. But if they differ in system settings like .net version, authentication and so on, you should launch your projects separately.
You're doing strange things, because MVC4 has initial support for WebApi. You can extract business logic from WebApi into another project. Do you really need to have WebApi controllers in separate project?
Related
I have ran into a scenario where I have added an App.Config file in a Class Library which I am referencing from my ASP.NET MVC project.
Now while publishing my Web project I can only see the DLL of the class library in the Bin folder but not the App.Config of the same. Is there any way to include that in the Web publish.
Thanks
You need to tell the compiler to copy these files to the output directory. To do so, select the app.config from the solution explorer and hit F4 for properties and select Copy Always like the below example
Your class library shouldnt be using the app.config file. Instead the driver application or consuming application should be having a single app.config and should feed this dll with parameters.
This will also help your application being more SOLID. Your class library should be doing single job. Reading from a app.config file adds a second responsibility.
Also, class library not reading from the app.config file make your class library loosely coupled and it can be taken anywhere.
I have to consume a WCF Service. I have multiple layers in my project. I have one output project and other are library projects. All are dll projects except one output project. I would like to know the best place to place my service references. This is one serious architecture related concern that I want to understand.
The best thing that I found is that App.config or Web.config are placed in output projects. I should add service references in output project only because it is it generates bindings and other endpoint details in config file only. I will be required to copy paste all the things in output project only if place it in dll projects.
You need to copy the WCF configurations into the main web.config or app.config project. Whatever the executing program is. Referenced here: Cannot call WCF WebService from DLL
Or don't use configurations at all, do it programmatically like here: WCF Configuration without a config file
I'm trying to understand ConfigurationManager in .NET by practicing it in different scenarios.
I have two projects: Project1 and Project2.
Project2 uses Project1.
My Situation: I have a section(serializedfilename) in my app.config file in project1.
and I have this line of code in a class1 of project1
private static string SerializedConfiguration = ConfigurationManager.AppSettings["SerializedFilename"];
In project2, I call a method in the class1 of project1 and i'm getting an exception.
its like .NET doesnt seem to be able to find the settings in app.config file of project1 when called from project2 even though i'v referenced project1 appropriately.
However, when i move the section(serializedfilename) to app.config file of project2...everything seems to work well...
Can someone explain to me what is happening here? I'm tempted to assume that ConfigurationManager only exist in the context of the client application(in this case project2) and not in the original application(project1 in this case)
Note: i'm new(1month+ to .NET)
Thanks.
When you add a reference app.Config is not copied. App.config needs to be in your primary project, in your case project 2. if you add it in project 2 and call it in the referenced object Project 1, you will not get any error as VS will pick it from your primary project.
Correct, ConfigurationManager looks to the executing assembly for the app.config or web.config to lookup settings.
So if your class library DLL that accesses configuration settings is running under a web site project then the app settings will need to be added to web.config, not the app.config of the class library.
So I'm trying to access a couple of IsInteger/IsNumeric functions from a custom class library I wrote in a separate project but within the same MVC4 solution.
I have a class library called MyHelpers (class library project) and the other is called Portal (a web application project), so two separate projects in the same MVC4 solution. After building MyHelpers successfully and putting the .dll in the Portal project's bin folder AND adding a reference to MyHelpers.dll, I still cannot find a reference to it in my Controller .cs file when adding the "using MyHelpers;" statement.
Why is this happening? Am I missing something? I thought that if I add a reference to the .dll and use the "using" statement it will let me reference the functions in the class library. What gives?
Please help and thanks much in advance.
In your MVC4 project, add a reference to your MyHelpers project. This way when you build MyHelpers again, your MVC4 project will have the most updated build of the MyHelpers.dll in the bin directory. You should not simply just reference the dll directly unless you have changed your output directory to the MVC4 project's bin directory. Be sure to check your output directories and make sure that all necessary dlls are in the directory of your MVC4 application.
So I'm trying to use a .Net Assembly in my web services project. This assembly requires lots of settings in App.config. But my web service doesn't have an App.config, it has a web.config. It seems that it uses sections that an app.config would have that don't even exist for web projects. Is there any way I can make this assembly work? (make it read another config file maybe?)
You should be able to simply use the same configuration sections in the web.config file that exist in the app.config and it would work.
The way the configuration subsystem works means that it does not matter.