referencing System.Windows.Automation - c#

I wanted to try out some of the automation stuff available through BugSlayer, but am having problems with the references.
I'm trying to figure out how to reference the System.Windows.Automation library in visual studio. I have the .NET Framework v3.5 installed, and VS 2008, but neither the UIAutomationClient nor System.Windows.Automation appear as a reference option in either the .NET or COM tabs for the references.
I can see the dll if I navigate to C:\WINDOWS\assembly\GAC_MSIL\UIAutomationClient\3.0.0.0__31bf3856ad364e35 through the command prompt, but if I browse to the assembly in Visual Studio, I can't actually get to the dlls.
Have I overlooked a simple way to include this in my project?

The UIAutomationClient.dll is located in this folder:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0
If you can't find in your Add Reference->.Net tab, then you have to use the Browse tab to go to the given path, and add the assembly (Right Click on the References, choose add reference, click browse tab).

add Uiautomationclient dll present under .net tab

I'm using Visual Studio Express 2015, and targeting to .NET 4.5. None of the answers worked for me. Here's what I had to do (after many minutes of looking through Add References -> Assemblies -> Framework and playing around. The reference I added is "UIAutomationClient". (There isn't any System.Windows.Automation" assembly in my list. Note that I also see assemblies "UIAutomationProvider", "UIAutomationTypes", and "UIAutomationClientsideProviders", but I didn't try any of those.)
Anyway, once I got the reference to "UIAutomationClient" added, then the using System.Windows.Automation actually worked okay.

For .Net coreapp 3.1, my fix is adding UseWPF into PropertyGroup of csproj file.
<UseWPF>true</UseWPF>

In VS 2015, you need to reference the UIAutomationProvider dll to use this Provider namespace. Just add a reference to this dll in your references folder. It's available in the Framework Assemblies of .NET.

Related

Visual Studio References versus Dependencies, Assemblies, and Packages

In Visual Studio 2019, in a .NET Framework (not .NET Core) console application project, how do I add NuGet packages so that they show up in the "Packages" section of a "Dependencies" instead of just as "References" with other assemblies? That is, I'd like to get this (which is from a Microsoft example app)...
... instead of this (which is what I have in my app after adding Newtonsoft.Json and MSAL using the NuGet package manager tool) ...
Notice, in my app, there is a "References" section but no "Dependencies" section, and the packages are mashed in with the other references. The only thing I could find to try was to right-click on References then select the "Migrate packages.config to PackagesReference", which yielded this ...
(StackOverflow bug? When I try to add a third image, it shows some totally random image in a different language. What the picture shows, though I can't get it to add, is the same "References" section except that the Json and MSAL references have a different icon.)
... which is closer (the packages are now "references", I guess) but there is still no Dependencies section with partitioned Assemblies and Packages subsections.
Assuming the MS example is doing it "right" and that I am doing it "wrong", how do I get from where I am to where they are?
Ah! I think I found the answer at Visual Studio 2017 References vs Dependencies. It appears I need to use a different project type if I want the newer style project file.

Visual Studio 2019 Error - Could not load file or assembly or one of its dependencies

I have some trouble with running my project. When I try to run, the following error appears:
FileNotFoundException: Could not load file or assembly 'Dapper,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified
Context:
I have a Class Library X and a Web Application Y which have dependencies on X. When I try to run my API project, it throws the above error.
BUT, when my colleagues try to run the same API project, it works fine (no errors, and in /bin folder, it loads all the .dll libraries..)
I did those approaches:
Restart Visual Studio, clean and build a solution
Remove the class library references and add it again
Tools > Import and Export Settings Wizard > Reset all settings (maybe some setting was not well configured). I also tried to import colleague settings and didn't work either.
I tried various approaches(even in a different machine, but same VS settings) but none of these worked for me.
Visual studio 2019 16.4 Enterprise.
I'd also try:
1) Deleting your bin and obj folders in your solution before a rebuild.
2) Check that you've not got multiple versions of the same package across the solution (right click on solution in solution explorer -> manage nuget packages for solution).
3) Check that the properties of the reference (right click in solution explorer on the reference in question) shows a path to the package that you'd expect relative to the solution (eg not in mydocuments/nuget packages or something!).
4) Try a fresh clone of the repo (this should in effect replicate your co-workers' set up) and see if the problem still exists then.
I suppose another cause could be that your coworkers have a locally installed package / dll that they're happily referencing without realising, but you don't have?
When you copy a project from someone or another system, you need to download and install all components. normally VS will give you the option to "restore packages" when you load a newly imported from git but not sure if it does when you open an existing solution from a different system.
Right Click your project, Manage Nuget Packages
Browse -> Search for Dapper. Install
In the error you receieve, it tells you what version of the package should be installed as well. Installing a significantly different version might cause other unexpected errors.
thank you for your solutions but I found the problem:
The project solution has some projects with .net standard 2.0 and some with .net framework 4.8. Somehow, when I run the app, some packages are not loaded correctly and it throws an error.
That line below solved my problem:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Put it in all .net framework 4.8 projects on first XML tag.
Thank your for all.
Regards.
I had exactly the same Dapper error message today when referencing a .Net Standard 2.1 class library in a .Net Core 3.1 WinForm app. My resolution was to double-click the class library name in Solution Explorer to open the .csproj file, and then add a CopyLocalLockFileAssemblies tag to the PropertyGroup tag and setting it to true.

Visual Studio 2012: Project cannot be referenced

We developed a large solution containing ~35 projects with VS 2010, now we are thinking about migrating to VS 2012 Ultimate.
I converted the solution file to VS 2012 and generally, everything works fine.
But whenever I open the solution, I get some warnings on a certain project A in the solution:
"The project X cannot be referenced"
"The project Y cannot be referenced"
...
where A has project-references to X and Y.
When I build the solution, I get errors that the Metadata of each respective DLL could not be found.
When I look at the references in the solution explorer, they are marked with a yellow warning-symbol. As soon as I simply click on the reference, the warning goes away and the icon looks normal. Then I can build without errors!
The problem occurs each time I open the solution, the affected projects are always the same.
Did anyone else experience this odd behavior?
Deleting and adding the project references again did not help...
Thank you in advance.
EDIT: I checked the csproj file of the referencing project and I wonder that all project reference GUIDs having the above problem are written lowercase, other projects are uppercased.
<ProjectReference Include="..\Presentation.Net\Presentation.Net.csproj">
<Project>{04004c6b-76c8-4f2d-9fcf-5a866bb80fd4}</Project>
<Name>CMS.Presentation.Net</Name>
</ProjectReference>
While within the solution the GUIDs are uppercased:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation.Net", "Presentation.Net\Presentation.Net.csproj", "{04004C6B-76C8-4F2D-9FCF-5A866BB80FD4}"
Any ideas?
VS 2012 dropped support for some of the older project types. Not all of the VS 2010 project types are supported in VS 2012. For instance, the MSI setup project types have been replaced by InstallShield LE project types. Check the compatibility list here and see if any of your failing project types are an issue.
This pointed me into the right direction.
Visual Studio 2012 Randomly reporting: "The referenced component X could not be found"
At least the warnings go away. Have to check whether the metadata errors will occur again.
When I ran into this problem, it was due to differing versions of .NET between the projects. You need to make sure that the project you are trying to reference has a compatible .NET version with the current project.
For example if your target project is .NET 4.5.2 and the project you reference is on 4.6, you can get this error as the referenced project is using components that your current project cannot access.
To solve it, simply go to the target project's properties and select the correct compatible version of .NET. For all my projects in my solution I maintain the same .NET version for each of them, especially if they are referencing each other.
Try to clean the project/solution and then build it.

System.web.extensions reference dll is missing from the 2.0 framework .net references in VS2010?

I'm having a similar problem as this person.
I'm trying to work with an old project that uses 2.0 framework in visual studio 2010. However it won't recognize that the System.web.extensions dll is part of that framework when it filters to 2.0 framework on the add reference dialog. And no, my framework is just set to ".NET Framework 2.0" as there is no 2.0-client.
Any help would be appreciated.
Right now I just manually went into the csproj file with notepad and added in the reference. This seems to work. Is there a way that I can do this with the other projects I'm working on, or will I just need to manually add it in the csproj files for each one?
I just had this problem with an old project I needed to work on.
I installed version 1.0 of the AJAX web extensions from http://go.microsoft.com/fwlink/?LinkID=77296 to get the older version of the file, then in my project, I referenced the dll by linking to System.Web.Extensions.dll in the folder C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025
The client profile feature was added with VS2008 SP1. It doesn't go back with client profiles for .NET 2.0 projects.
It seems that the System.Web.Extensions.dll assembly was not part of the GAC when installed - you had to manually include it in your bin directory. See this forum post for people having similar issues.
I would think you should be able to add the assembly by browsing for it when you add a reference instead of having to fire up Notepad and add it in that way.
I hope this helps. Good luck!

Where can I find the assembly System.Web.Extensions dll?

I'm messing around with some JSON and I'm trying to use the JavascriptSeralizer Class but I cannot for the love of god find a link to find where to add the assembly to my project. Someone help please!
Update
I'm using .NET 4.0 and its not in the .Net tab when you right click on references -> add reference in the solution explorer of Visual C# 2010.
I had this problem myself. Most of the information I could find online was related to people having this problem with an ASP.NET web application. I was creating a Win Forms stand alone app so most of the advice wasn't helpful for me.
Turns out that the problem was that my project was set to use the ".NET 4 Framework Client Profile" as the target framework and the System.Web.Extensions reference was not in the list for adding. I changed the target to ".NET 4 Framework" and then the reference was available by the normal methods.
Here is what worked for me step by step:
Right Click you project Select Properties
Change your Target Framework to ".NET Framework 4"
Do whatever you need to do to save the changes and close the preferences tab
Right click on the References item in your Solution Explorer
Choose Add Reference...
In the .NET tab, scroll down to System.Web.Extensions and add it.
EDIT:
The info below is only applicable to VS2008 and the 3.5 framework. VS2010 has a new registry location. Further details can be found on MSDN: How to Add or Remove References in Visual Studio.
ORIGINAL
It should be listed in the .NET tab of the Add Reference dialog. Assemblies that appear there have paths in registry keys under:
HKLM\Software\Microsoft\.NETFramework\AssemblyFolders\
I have a key there named Microsoft .NET Framework 3.5 Reference Assemblies with a string value of:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\
Navigating there I can see the actual System.Web.Extensions dll.
EDIT:
I found my .NET 4.0 version in:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Extensions.dll
I'm running Win 7 64 bit, so if you're on a 32 bit OS drop the (x86).
The assembly was introduced with .NET 3.5 and is in the GAC.
Simply add a .NET reference to your project.
Project -> Right Click References -> Select .NET tab -> System.Web.Extensions
If it is not there, you need to install .NET 3.5 or 4.0.
Your project is mostly likely targetting .NET Framework 4 Client Profile. Check the application tab in your project properties.
This question has a good answer on the different versions: Target framework, what does ".NET Framework ... Client Profile" mean?
I had this issue when converting an older project to use a new version of Visual Studio. Upon conversion, the project target framework was set to 2.0
I was able to solve this issue by changing the target framework to be 3.5.

Categories