I am using WebDriver and NUnit to create tests in C#. Is there a way to specify at runtime the URL and the Browser without having to change the code and rebuild?
Basically can I run the same tests against different URLs (Dev, QA , UAT etc) and different Browsers without having to recomplile.
Many Thanks.
After much searching I eventually came up with the solution by combining the best bits of two other incomplete solutions.
Config file should be the same name as your test file dll eg TestFile.dll.config and located in the same folder.
This is the format of your config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="TestURL" value="http://www.example.com/"/>
<add key="Browser" value="Firefox"/>
</appSettings>
</configuration>
Add a reference and a using statement for System.Configuration and use code like this to access your parameters:
testURL = ConfigurationManager.AppSettings["TestURL"];
browser = ConfigurationManager.AppSettings["Browser"];
All improvements, suggestions and comments are welcome.
We're building a .NET 4 WPF application that runs from a network drive. The application starts fine for me and most of my (developer) peers.
Recently, a software tester has joined our development team and was put in the same AD groups as I'm in.
Whenever he launches the application, this dialog pops up:
and the app naturally crashes after that.
When attaching a debugger, the debugger breaks at the first line of EF 4.4's DbContext constructor, for which the code is as follows:
public class CardioDanosContext : DbContext
{
// ...
public CardioDanosContext()
: base("CardioDanos")
{
// Irrelevant first line
As you can see, we call the DbContext's constructor with a connection string name which is defined in our app.config like so:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- ... -->
</configSections>
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="External;Resources;Base;Services;Modules;Data;"/>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="CardioDanos"
connectionString="Data Source={snip};Initial Catalog=CardioDanos;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<appSettings>
<!-- ... -->
</appSettings>
<!-- ... -->
</configuration>
Now, I'm assuming it is an issue with permissions, but we've verified all permissions for the affected user and they all seem in order. He can read and modify the app.config file without problems. I also assume it has something to do with running it from a network drive, but then again, it works fine for some of us.
I've not really found anything about this while searching the Internet, but does anyone have a clue why this could be happening?
Some googling tells me that some assemblies cannot be loaded. Are you sure that everything is correctly installed on the client? Any third party assemblies you are using that are installed in the GAC on your development machines, which are missing on the clients machine?
How are you deploying the application? Are you creating a publish, or are you just copying the bin/debug folder? If the last, then you are not including any specific referenced assemblies if you have not set 'Copy local' to True.
How is Entity Framework referenced? Are you using a NuGet package, or an old install which you have done manually?
this is my app.config file. I am using vs 2012 with c#.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Small_Business_Management.Properties.Settings.businessdataConnectionString1"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\businessdata.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
now i included the database file businessdat.mdf in the solution.Now when i publish the application it is not working in other computers.It works fine in mine. In other computers it asks me to install sql server.How can i publish with a local database so that it works without installing sql server in other computers
If you want to use the LocalDB functionality of SQL Server 2012 you need to install the LocalDB functionality on each device you deploy to. You can find the installer here.
It is possible to do a silent install, so you can include it in your application installer if you have one:
msiexec /i SqlLocalDB2012.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
more information here and here
If you really do not want to (or can not) install anything on the devices you deploy to, you can always check out sqlite
You basically have two choices:
Install LocalDB on the other computers - you may be able to integrate this into your installation/deployment process for the app.
Use an embedded database
To expand the above a bit, to avoid an installation you'll have to use an embedded database so that the necessary libraries are deployed with your application. In context the obvious choice would be SQL Server Compact which should work with the code and SQL you already have i.e. there's a reasonable chance you'll only need to add the files/references and change the connection string.
My Program uses EF to access data from a SQL CE database. When debug the application using debug setup it works fine but if I use release setup I get a MetadataException when the program tries to access the database through EF.
What I've checked so far:
Debug and release configuration is identical (same target platform)
The app.config is copied to the same directory as the executable (\Release)
The sdf database file is copied to \Release\
Metadata Artifact Processing is set to Embed in Output Assembly
Connection string name is identical in app.config and EF model
My app.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="GeoDataEntities" connectionString="metadata=res://*/Model.EF.Model.csdl|res://*/Model.EF.Model.ssdl|res://*/Model.EF.Model.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\GeoData.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
The assembly Model.EF is the namespace and Model the name of the edmx, I think that should be right.
I know that there a lot of posts and blogs about MetadataException and I've tried to solve this but nothing have worked so far.
Best regards
Jay
I really don't know what I've done but it's working since I've checked in and checked out from TFS.
I have a project in which I'd like to use some of the .NET 4.0 features but a core requirement is that I can use the System.Data.SQLite framework which is compiled against 2.X. I see mention of this being possible such as the accepted answer here but I don't see how to actually achieve this.
When I just try and run my 4.0 project while referencing the 2.X assembly I get:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional
configuration information.
What "additional configuration" is necessary?
In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include:
<?xml version="1.0"?><configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup></configuration>
The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work.
Note that this only matters for mixed mode (C++/CLI) assemblies. You can load all managed CLR 2 assemblies without specifying this in app.config.
This forum post on the .NET Framework Developer Center. It might provide some insight.
(Add to the app's config file.)
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Depending on what version of the framework you're targeting, you may want to look here to get the correct string:
http://msdn.microsoft.com/en-us/library/ee517334.aspx
I wasted hours trying to figure out why my release targeting .Net 4.0 client required the full version.
I used this in the end:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"
sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
Once you set the app.config file, visual studio will generate a copy in the bin folder named App.exe.config. Copy this to the application directory during deployment. Sounds obvious but surprisingly a lot of people miss this step. WinForms developers are not used to config files :).
Using 2.0 and 4.0 assemblies together isn't quite straight forward.
The ORDER of the supported framework declarations in app.config actually have an effect on the exception of mixed mode being thrown. If you flip the declaration order you will get mixed mode error. This is the purpose of this answer.
So if you get the error in a Windows Forms app, , try this, mostly Windows Forms apps.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
Or if the project is not Windows Form. In a Web project add this to web.config file.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
Was able to solve the issue by adding "startup" element with "useLegacyV2RuntimeActivationPolicy" attribute set.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
But had to place it as the first child element of configuration tag in App.config for it to take effect.
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
......
....
The above didnt work for me (I am working on a web app) - but this did...
Edit the sgen.exe.config file in the folder (I had to create one first);
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
(There is also one in v7.0 folder, but I didnt need to change that one, I am using VS2012)
The conents of the XML should look like this (same in previous answers)
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup>
</configuration>
If your are working in a web service and the v2.0 assembly is a dependency that has been loaded by WcfSvcHost.exe then you must include
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
in ..\Microsoft Visual Studio 10.0\Common7\IDE\ WcfSvcHost.exe.config file
This way, Visual Studio will be able to send the right information through the loader at runtime.
I ran into this issue when we changed to Visual Studio 2015. None of the above answers worked for us. In the end we got it working by adding the following config file to ALL sgen.exe executables on the machine
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
Particularly in this location, even when we were targeting .NET 4.0:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools
I used this config:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0"/>
<supportedRuntime version="v4.0"/>
</startup>
Worked for me
I had this problem when upgrading to Visual Studio 2015 and none of the solutions posted here made any difference, although the config is right the location for the change is not. I fixed this issue by adding this configuration:
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
To: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config
Then restarted Visual Studio.
I found a way around this after 3-4 hours of googling. I have added the following
<startup selegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
If this doesn't solve your problem then--> In the Project References Right Click on DLL where you getting error --> Select Properties--> Check the Run-time Version --> If it is v2.0.50727 then we know the problem.
The Problem is :- you are having 2.0 Version of respective DLL.
Solution is:- You can delete the respective DLL from the Project references and then download the latest version of DLL's from the corresponding website and add the reference of the latest version DLL reference then it will work.
I was experiencing this same error, and spent forever adding the suggested startup statements to various config files in my solution, attempting to isolate the framework mismatch. Nothing worked. I also added startup information to my XML schemas. That didn't help either. Looking at the actual file that was causing the problem (which would only say it was "moved or deleted") revealed it was actually the License Compiler (LC).
Deleting the offending licenses.licx file seems to have fixed the problem.
I was facing a similar issue while migrating some code from VS 2008 to VS 2010
Making changes to the App.config file resolved the issue for me.
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"
sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
Add following at this location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64
FileName: sgen.exe.config(If you dont find this file, create and add one)
<?xml version ="1.0"?>
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
Doing this resolved the issue
I Use
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
It's works but just before de </configuration> tag otherwise the startup tag doesn't work properly
Also i had this issue with the class library, If any one have the issue with the class library added to your main application. Just add
<startup useLegacyV2RuntimeActivationPolicy="true">
to you main application which would then be picked by the class library.