How can I get a unit test project in a (VS2015) solution for a WCF web service to use the same web.config file for its own app.config? I don't want to have to replicate all the settings that are in web.config in my app.config (and have to remember to keep them in sync). Thanks.
I was able to shift the relevant settings to a separate config file using this method. One thing to remember is that paths are relative to the WhateverTests\bin\Debug folder when referring to the other config file in the Whatever project.
Related
I have a WCF project which several other projects depend on, but others, like unit testing projects and other support utilities which don't need the service. It contains the following XML in the .csproj file:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
<WcfProjectProperties>
<AutoStart>True</AutoStart>
</WcfProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
Is there a way to get the "auto-start service with project" functionality to only apply to specific projects in the solution? Or is it all or nothing? Is there anything I could add to the other projects to tell them they depend on this service to make it auto-start in the debugging session? Or add some condition to the service's .csproj that depends on which project is the current startup project?
I tried experimenting with Condition="'$(Configuration)' == 'Debug'" in various places, but I couldn't get it to behave an different based on that Configuration variable.
To make the client applications debugable, create a new tiny project and set both the service and the client application as dependencies. The only file it should contain is Program.cs, and its only function should look like this:
[STAThread]
static void Main(string[] args)
{
new System.ServiceModel.ServiceHost(typeof(MyServiceClass)).Open();
MyClientApplication.Program.Main(args);
}
And then merge the app.config for both into a single app.config for this tiny application. But now the service is hosted inside the same process as the client, and they can both be debugged interchangeably.
This allows removing the AutoStart feature from the service, but still run the client application together with the service.
I have added new unit test project in VS 2015 for a method in my .net solution, while i run test case, the web config app settings values are null and unable to complete test, Actually the config key values are available and accessible during web app run, but during unit test the values are null,
can anyone please help me out.
Thanks in Advance
Test project needs app.cofig with similar settings present as in web project being tested.
Unit test is run in a separate app domain so needs it's own config file.
The ConfigurationManager reads the config file of the current app domain being run so create an app.config file for the test project and copy the desired configuration settings over to allow the tests to be exercised as expected.
This issue also exposes how your code is tightly coupled to implementation concerns in terms of the using the ConfigurationManager and you should consider abstracting configuration access so that they can be mocked/replaced to allow unit tests to be done in isolation.
I am developing an ASP.NET Web API v2 application. My application works fine from my DEV machine but when I go to deploy it to my server it gives the following errors.
The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
After searching Google, SO, and other sites I found adding a default Startup.cs class to my project fixed the issue. The problem is I don't know how.
What did adding Startup.cs do?
Why would my app compile and run on my development machine without Startup.cs?
This seems to involve OWIN but I was not even aware I was making use of any OWIN features.
This is most likely due to the way OWIN searches for its entry point (Startup class). In your dev environment you probably have a DLL in the project folder that has an OWIN Startup class. That dll is not being deployed as part of the deployment step and therefore doesn't exist in your deployed location.
Another posibility, along the same lines, is you're using .config transformations and you have defined a Startup class in your DEV config but not in your deployed config.
<appSettings>
<add key="owin:appStartup" value="StartupDemo.ProductionStartup" />
</appSettings>
OWIN Startup Class Detection might be informative.
MVC5 uses OWIN pipeline by default so it's "under the hood". Perhaps you migrated from a previous MVC site and that's why the Startup class was missing?
Cheers!
I am developing a webapplication using asp.net mvc 3.
In the solution I have a project for all the web/presentation things (models, views, controller) and in another project I have my services, daos and domainobject. now I created a config-file in my service-project with some settings. how can I access the file from my services?
If I don't set a path it uses the path of the asp.net exe.
Hope someone can help
Tobi
You can use AppDomain.CurrentDomain.BaseDirectory to get proper path.
Or change Build action property of your config file to Embedded Resource (msdn). After that you will be able to retrieve file using ResourceManager
i have a a new silverlight solution in visual studio. i have created a silverlight class library to share common functionality. this class library has a service reference and so it has a ServiceReferences.ClientConfig file. the problem is if i create a project in this solution and add a reference to the class library it seems that i need a ServiceReferences.ClientConfig in this individual project. if i copy and paste the ServiceReferences.ClientConfig file from the class library to the project, everything works fine. if i do not i get the error below. doesnt this defeat the purpose of sharing this service reference in a class library? i want to be able to change where the service reference points to (debug machine / production machine) easily in one place. what can i do? is there another way i'm missing? Thank you.
Cannot find 'ServiceReferences.ClientConfig' in the .xap application package. This file is used to configure client proxies for web services, and allows the application to locate the services it needs. Either include this file in the application package, or modify your code to use a client proxy constructor that specifies the service address and binding explicitly. Please see inner exception for details. >
The config for the class library is not packaged into the .xap file. Without that configuration, the service reference cannot be properly configured.
doesnt this defeat the purpose of sharing this service reference in a class library?
Not really. The bulk of the "service reference" is the code in the class library. This is what you are sharing. Since a xap (or exe and web app) has only one config file, you must have the ServiceReferences.ClientConfig in the application's config file.
I am not aware of a mechanism to copy some important bits from the config file of a class library to the application config file during a build.