C# using System.Xaml missing assembly reference - c#

I'm writing a C# Console Application that is targeted towards .Net 4.5. I want to use Xaml Services to save and read a List data structure to file. I'm using VS 2013 Pro.
The .net doc's say Xaml has been in .NET since 4.0(?) I have my projected targeted to 4.5, but even with 4.0, 4.5.1, 4.6, and 4.6.1... same missing assembly reference. I'm doing a
using System;
using System.Collections.Generic;
using System.IO;
using System.Xaml; // <-- this is getting the assembly error
using System.Xml;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
But that is where the missing reference is getting the error...
I've used it before in Win Forms. It is that maybe it's excluded for console applications? Or am I missing something that Xaml Class depends on before using that assembly?

Could it be that you did not add a project reference to the assembly "System.Xaml.dll"? The Xaml functionality is not contained in the assemblies which are included in a new VS console project by default. (Right-Click on the "References" entry of the project, then select "Add References", then browse to "Framework" and look for System.Xaml, which refers to the dll of that name).
A namespace however does not necessarily correspond uniquely to an assembly, so you might require even more assemblies. If you know which types you need, you can browse the MSDN documentation for looking which assembly might still be required.

Related

Is it possible to display package version numbers next to the usings?

Suppose that at the top of my *.cs file, I am including some dependencies:
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
Is it possible to also display version numbers here as shown below?
using System; //1.0.1
using System.Collections.Generic; //22.0.1
using System.IdentityModel.Tokens.Jwt; //3.56.2
etc
No, you can't. This is because C# and .NET is not like Java, TypeScript and other languages where the concept of namespaces, packages and libraries are combined - in .NET they're entirely separate: multiple packages can include the same library DLL file, and multiple library DLLs can contribute towards shared and different namespaces.
For example, the System namespace has its members in mscorlib.dll, System.dll, System.Core.dll, and others. None of these assemblies belong to any particular package as they're part of the BCL in your CLR implementation. Furthermore, anyone is free to declare their own types in namespace System.
With respect to "packages": the CLR is completely unaware of them: they're a design-time concern; instead all it cares about is what DLL files to link. You don't have to use NuGet packages at all (.NET developers survived just fine for the first 13 years without a built-in package manager).
Note that NuGet allows you to have multiple DLL files a single package, and the package author does not need to "own" (legally or otherwise) the DLLs contained within either, which means multiple NuGet packages can share the same assembly DLL, and those DLLs could share namespaces.
I take issue with these words of yours:
I am including some dependencies:
Remember, C# is not TypeScript - despite syntactic similarities (like C compared to C++) they're very different - it isn't appropriate to refer to namespace imports as "including dependencies" - it's just syntax - whereas in TypeScript the statement import { Foo } from './bar' is more than just syntax as it will invoke the runtime platform's package/module import system, whereas using in C# is an entirely inert statement that simply saves you from typing global::The.Full.Namespace.Name every time you use an identifier.

adding a dll to c# project and using the dll functions

enter image description hereI am trying to import a dll in my c# console project.
I add the dll in the reference of the project. Right Click->add reference->browse.
The DLL is placed in my project folder as well as in program data folder in c drive.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using mcp2210;
the last line "using mcp2210;" gives an error
Error 1 The type or namespace name 'mcp2210' could not be found (are
you missing a using directive or an assembly
reference?) C:\Users\testuser\AppData\Local\Temporary
Projects\ConsoleApplication1\Program.cs
Do I need to use [DllImport("mcp2210.dll")] in my project?
How can I access the functions of this dll?
Please see the images below
edit
Hi I was able to add the dll in my project using the namespace from the object browser. However when I try to run it in debug mode I get badImageFormatException was handled popup.
Could not load file or assembly 'mcp2210_dll_m_dotnetv2_x86, Version=1.0.5980.19136, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Why is this happening?
Namespace has nothing to do with a DLL's name. Just because the DLL is named mcp2210 doesn't mean it contains the namespace mcp2210.
After you've added the reference, open Visual Studio's object browser. Find the DLL in the treeview on the left and expand it to discover the namespaces and classes contained in it.
Once you find it, use one of its namespaces in your using statement and you're good to go.
If you cannot browse to your DLL, it is probably the wrong type of DLL or the wrong framework version.
Make sure if it is a managed dll. If it is build using unmanaged than place this dll in bin folder manually.
just copy paste in bin
Firstly, make sure both the dll project and your separate project have the same target platform (32 bit, 64 bit, or any cpu by going to the project's properties).
Secondly, make sure you have added the dll as a reference to your project. In addition to this, place the file in your project's 'bin > debug' folder.
The path should look like this (..\Your Project\bin\Debug).
If all of that fails, double check that the Target Framework matches in each project.

How do I designate the location of a library in order for a "using" statement to work (C#)

I'm used C# -some- but not recently.
I've got this header from some code, and it calls a custom non-system library, (Dynastream.Fit, at the bottom), but I need to know how to tell the program where it resides so it can compile. Pretty sure the library is in the SDK I downloaded, just need to find it. This is the FitSDK from ANT+.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using Dynastream.Fit;
You need to add the dll of Dynastream.Fit to your project Reference folder by right clicking the reference folder -> add reference -> Browse -> choose the dll; unless you have already installed the assembly in GAC.

Why is the reference for ConfigurationErrorsException missing from my .Net 3.0 application?

I have a .NET 3.0 Winform Application with a corrupt user.config file causing system config errors.
I wanted to improve handle these errors, similar to how it's done in this example on CodeProject.
To use '
However, when I try and use the 'ConfigurationErrorsException' to get the name of corrupted file I receive the following error:
The type or namespace name 'ConfigurationErrorsException' could not be found (are you missing a using directive or an assembly reference?)
I have only seen this error previously where there were .NET framework conflicts.
The project has the target framework .NET 3.0. The ConfigurationErrorsException was added in 2.0, so I didn't think there would be a framework conflict there.
The version 3.0 documentation is lacking compared to other versions and does say:
The current value is not one of the EnableSessionState values.
Which I'm not entirely sure what that implies (the documentation for EnableSessionState lead to more confusion rather than less).
Why does the program fail to build, with a type or namespace missing error?
Is this related to targeting .NET 3.0?
If so, Is there an alternative for .NET 3.0?
EDIT:
I have made sure to include 'using System.Configuration' at the top of my page. The total list of usings is:
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
using System.Configuration;
using System.Windows.Forms;
using System.Threading;
using ProjectName.Properties;
using System.Security.Permissions;
using Microsoft.Win32;

Why can't I reference System.Runtime.Serialization.Json in C#

I want to use an API to get info from the interwebz. The API returns data in Json format.
I'm running Microsoft Visual Studio C# 2010 Express addition.
It appears that I have the .NET Framework 4 Client Profile set as my
"Target framework" but I'm honestly not sure exactly what this
means.
This is a Windows Forms Application...
Not much code to show because I can't really get started without the appropriate using statement...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Net;
using System.Runtime.Serialization.Json;
I get this error:
The type or namespace name 'Json' does not exist in the namespace
'System.Runtime.Serialization' (are you missing an assembly
reference?)
Am I missing a DLL file or something? Based on my hours of fruitlessly searching for solutions, I understand that the .NET 4.xx should already have the tools needed to parse up a Json formatted string?
The System.Runtime.Serialization.Json Namespace is in two different DLL's depending on your .net framework.
In .NET 3.5 It is in System.ServiceModel.Web.dll
In .NET 4.0 and above It is in System.Runtime.Serialization.dll.
Make sure you have added the correct DLL as a reference in your project and add using System.Runtime.Serialization.Json; to the top of your code file.
EDIT - Consider using JSON.NET
Even though the .NET Framework supplies its own JSON Serialization and Deserialization namespaces (DataContractJsonSerializer and JavaScriptSerializer) you should investigate whether you would be better off using JSON.NET.
JSON.NET is easier to use, better performance and has far more features.
http://www.newtonsoft.com/json/help/html/JsonNetVsDotNetSerializers.htm
you need to import System.Runtime.Serialization dll from reference
You need to add a reference to your project.
In the Solution Explorer right click references then add reference. You'll see a list of DLL's and you have to check the box next to the one you need for it to be added to the project. After you've done this you can successfully add the using statement.
Hope that helps!
The general process for serializing and deserializing JSON from C# is:
Add a reference to the System.Runtime.Serialization library.
Add using directives for System.Runtime.Serialization and System.Runtime.Serialization.Json.
Please change your Target framework from .NET Framework 4 Client Profile to .NET Framework 4
I know this is an old question, but I came across this in .NET 5.0 and the solution is to add using System.Text.Json to the top of your code.

Categories

Resources