Where is the System.Net.Http.WebRequestHandler source code? - c#

To much fanfare it was announced that there was now a Roslyn powered index for the .NET Reference Source and that
The version of the framework that we currently have indexed is .NET framework
version 4.5.1.
Yet when I go there to look at HttpClient code all I get are stubs and I cannot find any code for the bits that make it run like System.Net.Http.WebRequestHandler.
Where can I find this code and why hasn't it been included already?

I found the solution on blogs.msdn.com:
"The WebRequestHandler is not included in the System.Net.Http DLL but rather in System.Net.Http.WebRequest DLL so you have to explicitly include that as a reference in order to see it."

add assembly System.Net.Http.WebRequest

Related

How do I add `System.Dynamic` to my project?

I am new to C# 4, especially the dynamic keyword. I have seen quite a number of tutorials and wish to try it out myself using VS 2012 Ultimate (MSDN).
Unfortunately I cannot seem to find System.Dynamic and cannot add a reference to it either. May I know where I can find the DLL for System.Dynamic and what I might have done wrong?
By default, VS 2012 already targets Fx 4.5, and System.Core is added as a reference.
The dynamic keyword is so common that when searching in Google yield a lot of un-related results.
Make sure you are targeting the .NET Framework version 4 or later.
Ensure your project references the System.Core assembly.
You will find the types and functionality of System.Dynamic in that assembly. Add the following line to your code files:
using System.Dynamic;
P.S.: In C#, in order for the dynamic keyword to work properly, you also need to reference the Microsoft.CSharp assembly. This assembly contains the late-binding functionality necessary for dynamic.
Whenever you want to search for documentation add msdn. Like msdn system.dynamic
You will find all the documentation you need.
System.Dynamic at MSDN
Namespace: System.Dynamic
Assembly: System.Core (in System.Core.dll)
The DLL is System.Core. Adding a reference to it will allow you to use the namespace System.Dynamic.

Warning: Can't find dll

I have a client program written in C# where one of the projects in the solution handles a case which the machine has SQL 2005 installed.
I have added the relevant DLLs, but I get that warning:
CA0060 : The indirectly-referenced assembly 'Microsoft.SqlServer.ManagedDTS, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' could not be found. This assembly is not required for analysis, however, analysis results could be incomplete. This assembly was referenced by: d:\Any CPU\Bin\Debug\MyProgram.SSIS2005.dll.
According to properties of Microsoft.SqlServer.ManagedDTS it's version is 9.0.3042.0, I don't understand why it requires the version 9.0.242.0.
I don't know if it related, but the version of Microsoft.SQLServer.DTSRuntimeWrap is 9.0.242.0.
What have I tried?
Deleting and adding the reference
Changing manually the version required in the csproj file
I thought about getting all dlls with the same version, but didn't find such a source at the web.
Any Ideas? Thanks, KM
EDIT:
Another details,
My target framework is .Net 4.0
I have set the 'useLegacyV2RuntimeActivationPolicy’ to true
Try to add the reference from:
C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ManagedDTS
And set the Local Copy for the reference in VS to true, hope this helps.
As far as I know SQL CLR is not currently compatible with .NET 4.0, you should try switching to 3.5 and see is that helps.
Check for the version of the system by going to:
C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ManagedDTS
If they are different then click on Add reference and follow the link to add the same.
Also in web.config, under the assemblies tag remove the one with the older version.
As #Mightymuke mentioned in the comments, Fuslogvw.exe shows which DLLs were loaded. One of my projects had a reference to DLL that referenced an old version of Microsoft.SqlServer.ManagedDTS.

Can't compile c# project because of some tuple error when referencing an external dll

I have an error, when I try to build my .net 4, c# project. Everything works great, but when I add an external reference to a given DLL, it stops working, it can't build, throws this type of some errors:
Error 36 The type 'System.Tuple' exists in both 'C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll' and 'C:\Projects\Project1\ExternalRefernces\SharpSNMP\SharpSnmpLib.dll' C:\Projects\Project1\CheckerStore.cs 17 21
Note, I did not do anything with the new library, just added as a reference. Any ideas?
You can solve this problem by specifying an external alias. Select the SharpSNMP reference in your project. In the properties window change Aliases from global to say SharpSNMP. In your code type this
extern alias SharpSNMP;
...
System.Tuple<T1,T2> sysTulpe;
SharpSNMP::System.Tuple<T1,T2> sharpTulpe;
or
extern alias SharpSNMP;
using SharpSystem = SharpSNMP::System;
...
System.Tuple<T1,T2> sysTulpe;
SharpSystem.Tuple<T1,T2> sharpTulpe;
See Aliases: overcoming name conflicts part 2: extern alias
What you can do is either change the target version to 3.5 or make some changes in the SharpSNMPLib. The source can be fetched from here or here.
The changes you need to make is specifically moving the System.Tuple type somewhere else.
Edit:
I belive you have added a reference to a precomplied DLL. A DLL that is NOT compiled for framework version 4. What you need to do is download the source code (see links above) and compile the project with target version 4.
Why you need to do this is because there are conditional build parameters depending on the framework target version. The SharpSNMPLib System.Tuple is used for version <= 3.5 and the framework System.Tuple is used for version >= 4.
Edit:
Reproduced your problem using framework System.Tuple and SharpSNMPLib.dll.
Successfully built SharpSNMPLib targeted on version 4.
Successfully built application using framework System.Tuple and the new SharpSNMPLib.dll.
Simply go to your CheckerStore.cs file, line 1721 (if I'm right). Find the Tuple class, and reference it using it's fully qualified name.
The library for some reason re-implements some system types. Likely reason is to make code to be source level compatible when using older versions of the framework.
Most likely there is a version of this SharpSNMP library that works with 4.0 framework. Check if you already have correct on in your source tree. Check with creators of the library what versions of the assembly you need to use with given framework version and what is recommended way of doing it.

"Missing compiler required member" error being thrown multiple times with almost no changes to code

Today after deploying some changes to a C# MVC site that I run, I went back to make some more modifications and came across this error:
Missing compiler required member System.Runtime.CompilerServices.ExtensionAttribute..ctor
The error is a bit vague (other than it's description, obviously) as it doesn't give me a file, line, or column to reference, only the project. Also, it throws the error a total of 20 times. I only made three changes to the code between the time I deployed (it was completely functional at that time) and now. I reverted my changes and it is still throwing the same error which makes no sense to me.
I haven't found a lot of information on this error on SO or Google, other than this guys solution and a couple references to some Mono project errors (I'm not using Mono). The solution the guy above gives requires adding a class definition that will allow the compiler to resolve the reference. I don't particularly want to do this because I haven't needed to do it up until this point and it will just muddy my code.
Just curious if anyone has run across this before.
In my case it was because the project was not referencing Microsoft.CSharp. Once I added a reference to that assembly, it compiled just fine.
I don't know if anyone else has experienced this, but I suddenly ran into this error after adding some code utilizing dynamic types and incorporating WebAPI into a project that originated as a TypeScript application in VS2013. Simply adding a reference to Microsoft.CSharp resolved my issue.
Hope this helps someone else.
This error usually means either your project is compiling against .NET 2.0 or you aren't referencing the correct version of System.Core.dll
For a near duplicate question, see Error when using extension methods in C#
I ran into this situation as well today. In my case I was referencing the Newton.Json.Net dll v3.5 in my .NET 4.0 application. I realized that I wasnt even using this library, thus once I removed it from my references, it no longer gave me the compiler error.
Problem solved!!!
The actual error comes from the fact that your 2.0 assembly that causes the error contains this code:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
The Code Above allows the .NET 2.0 Assembly to use extension methods (see Using extension methods in .NET 2.0?). While it confuses the compiler if you target .NET 4.0 and reference a 2.0 Assembly (containing above code) as the mscorlib.dll(4.0) contains the same class in the same namespace.
I fixed this
by compiling the original 2.0 assembly again without the attribute targeting 4.0
by removing the assembly (obviously)
by adding a third Extension Attribute in the target you compile (it seems to overrule the referenced definitions)
Writing this code somewhere in your project may solve your problem. It works for me
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
Probably you use dynamic keyword In .NetStandard Class library project. If so, you need to add a reference to Microsoft.CSharp library in the project. Hope it will resolve your problem.
NLog.dll 2.0 referenced from a .NET 4.0 project can cause this too.
I don't have a correct solution, but I'll add my data point:
In my case the error is caused by referencing GoogleSearchAPINet20
Here is what happens:
I close the solution that builds
I open the solution again. It still builds
As soon as I make any change and try to build, I get 19 "Missing compiler required member ..." errors
I remove the reference to GoogleSearchAPINet20
I add back the reference to GoogleSearchAPINet20
I build the solution. It builds without errors
I can now make code changes, build or perform any other actions with solution correctly as long as my Visual Studio is open
I close Visual Studio
Repeat from step one
I'm not referencing System.Core.dll in my solution at all and my target framework is .NET 4.
I'm a bit annoyed at this point ...
Got this error when trying to use async Tasks against .NET 4.0. Updating Target Framework to 4.5.2 fixed the problem.
I hit the same set of exceptions after I added some async methods to a winforms project. I needed to bump my .NET version from 4 to 4.5
For me, the problem occure when I add asynchronous method with async Task await in my .net4.0 project !
With previous versions of the .NET-Framework 4.5, you must install this package:
Install-package Microsoft.Bcl.Async –pre
or
Install-Package Microsoft.CompilerServices.AsyncTargetingPack
more info on Nuget or Nuget

The type or namespace name could not be found [duplicate]

This question already has answers here:
Getting "type or namespace name could not be found" but everything seems ok?
(44 answers)
Closed 8 years ago.
I have a C# solution with several projects in Visual Studio 2010.
One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). There is also a third project referenced by PrjForm, which it is able to reference and use successfully.
PrjForm references PrjTest, and PrjForm has a class with a using statement:
using PrjTest;
Reference has been correctly added
using statement is correctly in place
Spelling is correct
PrjTest builds successfully
PrjForm almost builds, but breaks on the using PrjTest; line with the error:
The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?)
I've tried the following to resolve this:
Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot)
Removed and re-added the reference and using statement
Recreated PrjForm from scratch
PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder
Loaded the solution on a different computer with a fresh copy of VS 2010
I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet.
What else could I try?
See this question.
Turns out this was a client profiling issue.
PrjForm was set to ".Net Framework 4 Client Profile"
I changed it to ".Net Framework 4", and now I have a successful build.
Thanks everyone!
I guess it figures that after all that time spent searching online, I find the solution minutes after posting, I guess the trick is knowing the right question to ask..
In my case I had:
Referenced DLL : .NET 4.5
Project : .NET 4.0
Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. I recompiled the .DLL to target .NET 4.0 and I was fine.
PrjForm was set to ".Net Framework 4 Client Profile" I changed it to ".Net Framework 4", and now I have a successful build.
This worked for me too. Thanks a lot. I was trying an RDF example for dotNet where in I downloaded kit from dotnetrdf.
NET4 Client Profile:
Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).
NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:
If you are building Server apps, Such as:
ASP.Net apps
Server-side ASMX based web services
If you use legacy client scenarios, Such as:
o Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
Use legacy Windows Workflow
Foundation 3.0 or 3.5 (WF3.0 , WF3.5)
If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll
Another thing that can cause this error is having NuGet packages that have been built with a newer version of .NET.
The original error:
frmTestPlanSelector.cs(11,7): error CS0246: The type or namespace name 'DatabaseManager'
could not be found (are you missing a using directive or an assembly reference?)
Further up in the log I found this:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3275: The primary reference "[redacted]\DatabaseManager\bin\Release\DatabaseManager.dll" could not be resolved because it has an indirect dependency on the assembly "System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
The solution was to re-install the NuGet packages:
http://docs.nuget.org/docs/workflows/reinstalling-packages
I solved mine because the other project was coded with .NET 4.5 and the other one was coded 4.0
The using statement refers to a namespace, not a project.
Make sure that you have the appropriately named namespace in your referenced project:
namespace PrjTest
{
public class Foo
{
// etc...
}
}
Read more about namespaces on MSDN:
Using Namespaces
I encountered this issue it turned out to be.
Project B references Project A.
Project A compiled as A.dll (assembly name = A).
Project B compiled as A.dll (assembly name A).
Visual Studio 2010 wasn't catching this. Resharper was okay, but wouldn't compile. WinForms designer gave misleading error message saying likely resulting from incompatbile platform targets.
The solution, after a painful day, was to make sure assemblies don't have same name.
It is also possible, that the referenced projects targets .NET 4.0, while the Console App Project targets .NET 4.0 Client Library.
While it might not have been related to this particular case, I think someone else can find this information useful.
The compiled dll should have public Class.
I had the same issue. The target frameworks were fine for me. Still it was not working.
I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. Then it started working for me.
Other problem that might be causing such behavior are build configurations.
I had two projects with configurations set to be built to specific folders.
Like Debug and Any CPU and in second it was Debug and x86.
What I did I went to Solution->Context menu->Properties->Configuration properties->Configuration and I set all my projects to use same configurations Debug and x86 and also checked Build tick mark.
Then projects started to build correctly and were able to see namespaces.
Changing the framework to
.NET Framework 4 Client Profile
did the job for me.
For COM/ActiveX references, VS 2012 will show this error right on using statement. Which is quite funny, since it's saying that may be you are missing a using statement.
To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug.
If your project (PrjTest) does not expose any public types within the PrjTest namespace, it will cause that error.
Does the project (PrjTest) include any classes or types in the "PrjTest" namespace which are public?
just changed Application's target framework to ".Net Framework 4".
And error got Disappeared.
good luck;
:D
check your Project Properties, your Reference Paths should be empty like this:
Regards

Categories

Resources