UIAComWrapper assembly is throwing error while building solution - c#

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.

Related

Could not load file or Assembly `System.Windows.Forms , Version=4.0.0.0` cannot find the file

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

Dnspy compilation error without editing the code

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;

Instantiating a class produces ReflectionTypeLoadException at Assembly.GetTypes()

I discovered that after my application generates Telerik report
var result = new ReportProcessor().RenderReport("PDF", new InstanceReportSource { ReportDocument = new MyTelerikReport(data) }, null);
var stream = new MemoryStream(result.DocumentBytes);
return CreateHttpFileResponse("MyReport.pdf", stream, "application/pdf");
I am not able to get all types within CurrentDomain
var typesWithAttribute = (from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes() //error appears here
//some filtering logic
select t).ToList();
I am getting error
System.Reflection.ReflectionTypeLoadException: Unable to load one or
more of the requested types. Retrieve the LoaderExceptions property
for more information.
LoaderExceptions:
System.IO.FileNotFoundException: Could not load file or assembly
'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified. File name:
'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
After some investigation I found that assembly that fails to load: Telerik.Reporting.OpenXmlRendering, Version=8.0.14.311, Culture=neutral, PublicKeyToken=a9d7983dfcc261be and that assembly doesn't exists in AppDomain.CurrentDomain.GetAssemblies() before I generate report (I assume that assembly loaded dynamically by Telerik.Reporting, Version=8.0.14.311, Culture=neutral, PublicKeyToken=a9d7983dfcc261be).
I could filter out that assembly as I don't need any types from that but I am a bit worried about fact of having assemblies in domain that cannot be loaded - seems a bit wrong to me.
Could someone explain what there happens? Is it my issue or that is fault of 3rd party library that doesn't load all required assemblies?
The issue is not the assembly but the Type coming from a dependent assembly that has not been loaded.
If the GetTypes method is called on an assembly and a type in that assembly is dependent on a type in an assembly that has not been loaded (for example, if it derives from a type in the second assembly), a ReflectionTypeLoadException is thrown.
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes(v=vs.110).aspx

BindingFailure was detectedMessage with Mono.Addins

I'm using Mono.Addins for my project. Here my code :
static void Main()
{
string modulepath = String.Format("{0}\\{1}", Loader.GetCurrentDirectory(), "modules");
AddinManager.Initialize(modulepath, modulepath);
AddinManager.Registry.Update(null); //**Error in here**
}
I'm get an error :
The assembly with display name 'Mono.Addins.CecilReflector' failed to load in the 'Load' binding context of the AppDomain with ID 2. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Addins.CecilReflector, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
File name: 'Mono.Addins.CecilReflector, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
Any ideas to solve this problem. Thank in advance.
Yeah my problem is solved by copy file Mono.Addins.CecilReflector to application path. Thank Ieppie.

Get Assembly Names in Current Application Domain

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.

Categories

Resources