I'm getting the following exception when I try to run a test with FluentAutomation
A first chance exception of type 'System.IO.FileLoadException'
occurred in FluentAutomation.Core.dll
Could not load file or assembly 'WebDriver, Version=2.25.1.0,
Culture=neutral, PublicKeyToken=1c2bd1631853048f' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Here's the stack trace
at FluentAutomation.SeleniumWebDriver.b__0(TinyIoCContainer
container)
at FluentAutomation.FluentTest.get_I()
I've got the latest version of selenium from nuget but seems like there's some kind of hardcoded required version from within the fluentautomation dll
FluentAutomation genuinely looks amazing so would be great to be able to use it in my project.
#stirno please help!
FluentAutomation and selenium 2.32.1.0 looks decidedly similar to my problem but I've downloaded the latest ChromeDriver from Nuget and I'm copying it into my bin directory as prescribed.
I've also tried downloading the latest from here and copying that in. No joy
I'm also using spec flow so here's my setup in case it helps...
[Binding]
public class WebScenario : FluentAutomation.FluentTest
{
private readonly IObjectContainer objectContainer;
public WebScenario(IObjectContainer objectContainer)
{
this.objectContainer = objectContainer;
FluentAutomation.Settings.ScreenshotPath = #"C:\Work\Temp";
FluentAutomation.Settings.ScreenshotOnFailedExpect = false;
FluentAutomation.Settings.ScreenshotOnFailedAction = false;
FluentAutomation.Settings.DefaultWaitTimeout = TimeSpan.FromSeconds(1);
FluentAutomation.Settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(30);
FluentAutomation.Settings.MinimizeAllWindowsOnTestStart = true;
}
[BeforeScenario("Web")]
public void BeforeScenario()
{
FluentAutomation.SeleniumWebDriver.Bootstrap(FluentAutomation.SeleniumWebDriver.Browser.Firefox);
objectContainer.RegisterInstanceAs<INativeActionSyntaxProvider>(I);
}
}
The exception happens when I is accessed for the first time injecting it into the PageNavigator object
If you're interested you can download a really simple source example from github
So I got this working... I downloaded the FluentAutomation source from GitHub and built the latest dlls and dropped them in. Looks like this problem should be dealt with in the next release :D
Getting the latest source from the github repo and dropping in the built dlls worked for me
Related
I have an application that has all the DLL files it needs embedded into it so that it is a standalone exe. Here is how I am loading everything now:
public static Assembly ExecutingAssembly = Assembly.GetExecutingAssembly();
public static string[] EmbeddedLibraries = ExecutingAssembly.GetManifestResourceNames().Where(x => x.EndsWith(".dll")).ToArray();
public static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) {
// Get assembly name
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
// Get resource name
var resourceName = EmbeddedLibraries.FirstOrDefault(x => x.EndsWith(assemblyName));
if (resourceName == null) {
return null;
}
// Load assembly from resource
using (var stream = ExecutingAssembly.GetManifestResourceStream(resourceName)) {
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
return Assembly.Load(bytes);
}
}
public static void Main(string[] arg) {
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
RealMain();
}
So the first interesting thing I noticed is that it only loads the DLL files that are used in the first page. It isn't enough to put using System.Data.SQLite; at the top to get it to include System.Data.SQLite.dll, you also have to do something that touches that namespace right away.
The next issue involves SQLite.Interop.dll which it won't load into the assembly. When you try you get the following error:
Exception thrown: 'System.BadImageFormatException' in mscorlib.dll
An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
Now I could unpack the DLL and copy it to the c:\Windows\System32 directory, but since everything else is self contained, it would be nice if this was as well. I noticed this SDK that claims to be able to create it as a virtual file:
https://www.boxedapp.com/boxedappsdk/usecases/embed_system.data.sqlite.dll_dependencies.html
Is there a way to do this without the extra SDK? Or as an alternative, is there another way of creating and using SQLite databases without that DLL using a different package? I tried 3-4 different packages yesterday and didn't get anywhere.
SOLUTION
Ok, so this is disappointing that it is so easy, and yet nowhere else did I see the solution in dozens of other SO questions. On the SQLite.org website, there are a couple different downloads to choose from. When you use the NuGet package manager, you get the wrong version if what you want to do is embed everything.
To do it right, go to: https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
On that page you will want to download the BUNDLE version. In my case that was sqlite-netFx46-static-binary-bundle-Win32-2015-1.0.112.0.zip
Manually add that as a resource, include in your application as an Embedded Resource (Those are 2 separate steps), set it to not copy to output directory and use the code from the question to have it added.
I've got serious trouble with Mono behaviour. My application uses System.Component.Composition to load plugins. Those plugins are place in subfolder of my program. Let me show you:
+ProgramFolder
--Program.exe
--ProgramCore.dll
-+PluginsFolder
--+Plugin1Folder
----Plugin1.dll
----SomeLibrary.dll (it's dependence which is used by Plugin1.dll)
---Plugin2
And it works pretty well when runned in native windows environment. But as soon as I would like to run it in MONO environment it fails with error
Could not load file or assembly 'Plugin1' or one of its dependencies. The system cannot find the file specified.
In my app.config i placed in assembly binding section such probing
<probing privatePath="PluginsFolder/Plugin1Folder"/>
to allow my program search for dll's here but it looks that MONO ignore this section. How to make it work in MONO?
I found solution. It's second time I see that MONO works totally diferrently than native Windows environment. I had to rewrite method and now, it works on both environments as expectected.
So this is that class with appropiate method:
class ModulesLoader
{
[ImportMany(typeof(ISchedulable))]
public IEnumerable<ISchedulable> Modules { get; set; }
private string dir;
private string name;
public ModulesLoader(string directory, string name)
{
Assert.ThrowIfEmptyString(directory);
Assert.ThrowIfNull (name);
this.dir = directory;
this.name = name;
}
public void Load()
{
var catalog = new AggregateCatalog();
var assembly = GetType ().Assembly; //Assembly of our executable program
var dllCatalog = new AssemblyCatalog (assembly);
catalog.Catalogs.Add(dllCatalog);
var pluginAssembly = Assembly.LoadFrom (Path.Combine (dir, name)); //We have to explicit point which assembly will be loaded
var pluginCatalog = new AssemblyCatalog (pluginAssembly); //pass it to catalog to let framework know each vital information about this .dll
catalog.Catalogs.Add (pluginCatalog);
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this); //and it works!
}
}
There was second problem too. System.Configuration dll wasn't marked as 'Copy local' and MONO throws InvalidProgramException which inform that method body is empty. Finally, I get manage to make it work xD
Writing platform agnostic software sometimes is really weird xD
I've got a test class that looks like:
// disclaimer: some type names have been changed to protect IP,
// there may be inconsistencies
using Moq;
using MyComp.MyProj.DataAccessLayer;
namespace Test.Common.Data.DataAccessLayer
{
public class Test
{
Mock<IApplicationData> appData;
Mock<IConfig> config;
public Test()
{
this.appData = new Mock<IApplicationData>();
this.config = new Mock<IConfig>();
}
[Fact]
public void GetNewInstance_WithoutUser( )
{
this.config.Setup(c => c.GetConfigInt(It.IsAny<string>())).Returns(1);
// DalFactory is a type in MyComp.MyProj.DataAccessLayer
var dal = DalFactory.GetDataAccessLayer(1, "fakestring", (IApplicationData)this.appData.Object, (IConfig)this.config.Object);
Assert.IsType <IDataAccessLayer>(dal);
}
}
}
```
The problem here is that whenever it tries to access the DalFactory type, it throws this exception:
System.TypeLoadException : Could not load type 'MyComp.MyProj.DataAccessLayer.DalFactory' from assembly 'DataAccessLayer, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null'.
The Version is the key there, since the MyComp.MyProj.DataAccessLayer is in an assembly with Version 8.0.x while the test is in an assembly with Version 0.9.0 (or 1.0.0 or 0.0.1, I've tried several values).
Question is, why would Moq be trying to load the wrong assembly for this type?
I've tried: looking in the GAC to see if there's an assembly being loaded from there, re-adding the project references, changing AssemblyTitle in the test AssemblyInfo.cs, changing the name of the class the test is in and using an alias on the using statement. No effect.
The method for GetDataAccessLayer is a public static so I don't think InternalsVisibleTo factors in here. If I F12 navigate to the type being tested, it goes fine, gets to the right place.
If I put Assert.True(1 == 1); as the only thing in the Test method, it runs fine and passes.
What should I try next to fix this issue?
Try:
re-build your code in MyComp.MyProj.DataAccessLayer project
re-build Test project
run tests again
see if that helps
Also make sure the client Target Framework is the same for both projects (Properties > Application > Target Framework)
Recently in my WinForm project, I installed MiniProfiler.Windows and write following decorator for my QueryHandlers(I'm using CQRS):
public class MiniProfilerQueryHandlerDecorator<TQuery,TResult>:IQueryHandler<TQuery,TResult> where TQuery : IQueryParameter<TResult>
{
private readonly IQueryHandler<TQuery, TResult> _decoratee;
public MiniProfilerQueryHandlerDecorator(IQueryHandler<TQuery, TResult> decoratee)
{
_decoratee = decoratee;
}
public TResult Handle(TQuery request)
{
TResult result;
using (StackExchange.Profiling.MiniProfiler.Current.Step("Call QueryHandler"))
{
result =_decoratee.Handle(request); //call some Linq to entity queries
}
var friendlyString = ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings();
Debug.WriteLine(friendlyString);
return result;
}
}
I get following error at var friendlyString=ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings()
line.
An unhandled exception of type 'System.MissingMethodException' occurred in IASCo.Application.Core.dll
Additional information: Method not found: 'Boolean StackExchange.Profiling.MiniProfiler.get_HasSqlTimings()'.
Does anyone know where is the problem?
MissingMethodException = an attempt is made to dynamically access a deleted or renamed method of an assembly that is not referenced by its strong name (msdn).
Or as this answer puts it:
This is a problem which can occur when there is an old version of a DLL still lingering somewhere around
I notice that the MiniProfiler.Windows library is using a very old (over 2 years) version of MiniProfiler. That version of the code did indeed have a MiniProfiler.HasSqlTimings property. However, the current version (3.0.11) no longer has this property.
I am guessing that you are using the code from the MiniProfiler.Windows library that you linked above, but instead of using the v2 MiniProfiler dll that they have saved in /packages, you are using a v3 MiniProfiler dll (maybe downloaded from nuget). This would explain the exception that you are getting.
If this is indeed the case, then you can solve this by either downloading the version 2.0.2 nuget (Install-Package MiniProfiler -Version 2.0.2) or by upgrading the code in ConsoleProfiling to be compatible with MiniProfiler v3.
I am getting started with developing an Excel-DNA addin using IronPython with some C# as a wrapper for the calls to IronPython. With the generous help of the Excel-DNA developer, I have worked through some of the initial kinks of getting a sample up and running, but now I am trying to debug the addin in SharpDevelop, and I'm running into some problems. As I'm completely new to most of this, I'm not really sure if it is an issue with SharpDevelop, .NET, Excel-DNA or IronPython.
I have created two projects in one solution, one is a C# class library. The other is a python class library. I setup the project to debug following a tutorial I found on a blog. I am able to step through the first few lines of C# code, so that is progress, but when I get to the following line:
pyEngine.Runtime.LoadAssembly(myclass);
I get an exception:
"Could not load file or assembly
'Microsoft.Dynamic, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)"
But I'm pretty sure I have added the Microsoft.Dynamic reference to my project. It is version 1.1.0.20. This is included in the IronPython distribution but also in another location on my computer. I have tried setting the reference to both, but they both have the same version number and appear to be the same file size. Neither one works. Do I need version 1.0.0.0 or am I doing something else wrong? I don't really understand why anything pyEngine (the ScriptEngine returned by Python.CreateEngine()) would try to load a different version than the one included with the distribution.
Code is below. Let me know if you need any other information.
MyAddin.cs
/*
Added these references all as Local Copies - probably not necessary?
System.Windows.Forms
Microsoft.CSharp
ExcelDna.Integration (from Excel-DNA distribution folder)
IronPython (from IronPython folder)
IronPython.Modules (from IronPython folder)
Microsoft.Dynamic (from IronPython folder)
Microsoft.Scripting (from IronPython folder)
Microsoft.Scripting.Metadata (from IronPython folder)
mscorlib (I don't really know why I added this, but it was one of the references in my IronPython class library)
MyClass (this is the reference to my IronPython class - I checked to see that it gets copied in every time I rebuild the solution and it does)
These were automatically added by SharpDevelop when I created the project.
System
System.Core
System.Windows.Forms
System.Xml
System.Xml.Linq
*/
using System;
using System.IO;
using System.Windows.Forms;
using ExcelDna.Integration;
using System.Reflection;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public class MyAddIn : IExcelAddIn
{
public void AutoOpen()
{
try
{
string xllDirectory = Path.GetDirectoryName(#"C:/Users/myname/Documents/SharpDevelop Projects/IronPythonExcelDNATest/MyAddIn/bin/Debug/");
string dllPath = Path.Combine(xllDirectory,"MyClass.dll");
Assembly myclass = Assembly.LoadFile(dllPath);
ScriptEngine pyEngine = Python.CreateEngine();
pyEngine.Runtime.LoadAssembly(myclass);
ScriptScope pyScope = pyEngine.Runtime.ImportModule("MyClass");
object myClass = pyEngine.Operations.Invoke(pyScope.GetVariable("MyClass"));
IronTest.AddSomeStuff = pyEngine.Operations.GetMember<Func<double, double,double>>(myClass, "AddSomeStuff");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public void AutoClose()
{
}
}
public class IronTest
{
public static Func<double, double, double> AddSomeStuff;
public static double TestIPAdd(double val1, double val2)
{
try
{
return AddSomeStuff(val1, val2);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return double.NaN;
}
}
}
MyClass.py
class MyClass:
def __init__(self):
pass
def AddSomeStuff(self,x,y):
return x + y
Your IronPython stuff probably needs to run under the .NET 4 runtime. To tell Excel-DNA to load .NET 4, you have to explicitly add a RuntimeVersion attribute in the main .dna file. Your .dna file will start with something like:
<DnaLibrary RuntimeVersion="v4.0"> ... </DnaLibrary>
The default behaviour, if the attribute is omitted, is to load the .NET 2.0 version of the runtime (which is also used by .NET 3.0 and 3.5).
It might be possible to host IronPython under the .NET 2.0 runtime, but then you need to deal with the DLR libraries yourself, whereas they are built-in and already installed with .NET 4.