The 'ConnectionState' exists in both 'System.Data.Common, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
bool flag2 = this.sqlite_conn.State != ConnectionState.Open;
if (flag2)
{
this.sqlite_conn.Close();
this.sqlite_conn.Open();
}
Getting above error in this line of code while using dnspy.
Error code is CS0433 from main.cs
Check your project references and using statements and remove any unused ones.
Try to explicitly put the proper namespace in front of your enum, like:
System.Data.ConnectionState.Open;
Related
I am using reflection to search through assemblies that contain a certain interface, the one i am trying to find is a windows form that implements that interface, however the error i am getting claiming it cannot load the file, could it be down to not using reflection correctly or loading in the file properly.
string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.dll");
foreach (string file in files)
{
try
{
Assembly da = Assembly.LoadFrom(file);
foreach (Type type in da.GetTypes())
{
debugger = (IDebugger)Activator.CreateInstance(type.GetInterfaces().First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDebugger)));
break;
}
break;
}
catch (Exception e)
{
Console.WriteLine("{0}: {1}", file, e.ToString());
continue;
}
}
if (!(debugger == null))
debugger.VirtualMachine = this;
Error
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at SVM.SvmVirtualMachine..ctor() in C:\Users\Ollie\Desktop\Work\SimpleVM\SVM\VirtualMachine\VirtualMachine\SvmVirtualMachine.cs:line 49
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
File name: 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Value of the File
C:\Users\Ollie\Desktop\Work\SimpleVM\SVM\bin\Debug\Debugger.dll: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Help from Lecturer - Fix (Only Fix available atm i believe)
- In the .csproj file
- Change <Project Sdk="Microsoft.NET.Sdk"> change this to <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
- the <PropertyGroup> element with OutputType and TargetFramework nested inside it. Add a nested child before the </PropertyGroup> tag: <UseWindowsForms>true</UseWindowsForms>
- Save and Rebuild
Automation solution is cleaning and building properly but while building it using build definition its throwing error,
Its checking with the file on location where we are saving the builded solution .dll files and throwing error:
Desktop\Pages\NewFieldPropertiesPage.cs(729,45): error CS1705: Assembly 'Aptean.Windows.Automation' with identity 'Aptean.Windows.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'UiaComWrapper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'UiaComWrapper' with identity 'UiaComWrapper, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [C:\agent-DGA1BDT04TFS13_work\1\s\Respond.Test.Base\Respond.Test.Base.csproj]
This is how we define automation element:
and getting error findin "AutomationElement" and "PropertyCondition" which is coming from "System.Windows.Automation" assembly
``` {
``` get
``` {
``` AutomationElement root = AutomationElement.RootElement;
``` PropertyCondition PropApplicaionRoot = new PropertyCondition(AutomationElement.AutomationIdProperty, "MainForm");
``` AutomationElement ApplicationRoot = root.FindFirst(TreeScope.Subtree, PropApplicaionRoot);
``` PropertyCondition PropSideMenuRoot = new PropertyCondition(AutomationElement.AutomationIdProperty, "pnlObjectAndFieldDetails");
``` AutomationElement SideMenuRoot = ApplicationRoot.FindFirst(TreeScope.Subtree, PropSideMenuRoot);
``` PropertyCondition propEntitiesAndFields = new PropertyCondition(AutomationElement.NameProperty, "Boolean Field 135374");
``` AutomationElement OKButton = SideMenuRoot.FindFirst(TreeScope.Subtree, propEntitiesAndFields);
``` return OKButton;
``` }
``` }
Below is the error i am getting, one of the error statement:
Respond.Test.Base\Desktop\UIMap\SelectSkillPageMap.cs (30, 45)
Respond.Test.Base\Desktop\UIMap\SelectSkillPageMap.cs(30,45): Error CS1705: Assembly 'Aptean.Windows.Automation' with identity 'Aptean.Windows.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'UiaComWrapper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'UiaComWrapper' with identity 'UiaComWrapper, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Actually we are checking in the correct file and solution was also building, while digging deep in the error mentioned,
It was only failing when building using the source solution in a VM, where when getting latest was not changing the reference file.
Deleted the solution from the location and then ran the VNext build has resolved the issue as this time it took the latest versions of .dll files from source.
Thanks.
I am using VS2015 with Resharper for WebAPI 2.0 project. Trying to use System.Net.Http.HttpRequestMessageExtensions.GetRequestContext gives me an error saying
Error CS0433 The type 'HttpRequestMessageExtensions' exists in both 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I've tried editing web.config to read
<compilation debug="true" targetFramework="4.5.1" batch="false" />
Also as suggested in numerous posts - restarted visual studio, clear resharper cache, rebuild the solution.
Nothing helps and I am still seeing this error. Any other suggestions?
You need to use a “extern alias” to manage two classes with the same namespace.
First, define de name of your custom alias in the properties of the assembly:
Then, in the code:
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
extern alias Alias1;
extern alias Alias2;
using namespace1 = Alias1::System.Net.Http.HttpRequestMessageExtensions;
using namespace2 = Alias2::System.Net.Http.HttpRequestMessageExtensions;
public class HomeController : Controller
{
public void Test()
{
// ...
namespace1.GetRequestContext(request);
//namespace2.GetRequestContext(request); // error
}
when i add Microsoft.WindowsMobile.Status; reference and code
private SystemState displayRotationState = new SystemState(SystemProperty.DisplayRotation);
i get
Error 1 The type 'Microsoft.WindowsMobile.IApplicationLauncher' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.WindowsMobile, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. C:\Projekti\Skladiscenje\Skladiscenje\Skladiscenje\CustomForms\NonFullscreenForm.cs 12 25 Skladiscenje
what is wrong and how to solve it?
As the error clearly tells you, you should also add a reference to the assembly:
Microsoft.WindowsMobile
after you do this it should work, ops, compile at least :)
I want to get Assemblies Friendly Names in Current Application Domain and hence I wrote something like this :
static void Main(string[] args)
{
foreach (System.Reflection.Assembly item in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(item.FullName);
}
}
But the problem is this is the output what I got rather than what I desired to see :
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e0
ApplicationDomains, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
Actually I was expecting those names :
alt text http://www.pixelshack.us/images/xjfkrjgwqiag9s6o76x6.png
Can someone tell me if there is something I mistook.
Thanks in advance.
Or the names I was expecting weren't assemblies ?
You won't always get the pretty namespace names when you use reflection, you get the real names of the assemblies.
You also won't get all referenced libraries, only the ones that CURRENTLY loaded. If you add "XmlDocument foo = new XmlDocument()" above your code, System.XML will show up.
static void Main(string[] args)
{
XmlDocument foo = new XmlDocument();
foreach (System.Reflection.Assembly item in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(item.FullName);
}
}
Output:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
ConsoleApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
It's impossible to get list of all referenced assemblies during runtime. Even if you reference it in your visual studio project, if you don't use them, C# compiler will ignore them and therefore they won't make it into your output file (exe/dll) at all.
And for the rest of your assemblies, they won't get loaded until they are actually used.
AppDomain.CurrentDomain.GetAssemblies() gives you array of all loaded assemblies and this list could be very different from what you see in visual studio project.
foreach(var assem in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(assem.GetName().Name);
}
Assembly.GetName() returns an AssemblyName object which has a Name property. That's what you're looking for.
Either use Assemly.GetName().Name or use reflection to find the AssemblyTitleAttribute and use that value.