I am trying to import the WebRequestHandler class in a .vb file that is located in the App_Code folder in a Web Forms application using .net framework 4.6.
This does not work and shows a compiler warning when in the class file saying ‘WebRequestHandler is not defined’.
Importing and using the WebRequestHandler class works fine in the same project outside of files contained in the App_Code folder.
I have made sure I am using the correct import statement i.e. System.Net.Http.
In the web.config I am targeting .net framework 4.6, WebRequestHandler is available from 4.5 onward.
I have tried installing Microsoft.CodeDom.Providers.DotNetCompilerPlatform version 3.6 and adding the following to the web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+" />
</compilers>
</system.codedom>
I know that the App_Code is compiled at run time and when trying to run the application it will throw a run time error, but I don’t understand why I am able to use the WebRequestHandler in other files outside of the App_Code folder.
Is there a setting somewhere that I am missing to be able to use WebRequestHandler?
Andy Thompson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.