Always tell what actually happens rather than just that "it doesn't work". Error messages are intended to tell you (and us) what goes wrong rather than having to guess.
I'm not even sure if you mean this is a runtime error rather than a compile time error. It could be anything that causes this line to fail including this WebApiConfig class to be not declared at all or not properly ???)
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'WebApiConfig' does not exist in the current context WebAPI-DI V:\ETC Projects\Dependency Injection for Web API Controllers\C#\WebAPI-DI\Global.asax.cs 14 Active
The compiler error is telling you the compiler cannot find WebApiConfig.Register. Usually this is due to a missing "using" statement at the top of the file (Global.asax.cs).
Place your cursor over the error, Visual Studio should pop up a help window that displays a list of possible fixes including adding the "using" line.
There can be other issue with your code.
Unfortunately, you did not share the WebApiConfig.cs file so we cannot see if the namespaces match. The standard Visual Studio templates add this configuration automatically. Are you trying to configure Web API by hand? If
so, create a new project and review the template code. Compare the template code to your code.
gebhard, i am happy to say that i fixed the error in the Api project. It was the WebApiConfig file. I was trying to hand build it so that why it failed. But when i compared the code i could see what to do to resolve the issue thanks. Markus.
Member
251 Points
423 Posts
Application Start error.
Dec 03, 2019 11:59 PM|Markus33|LINK
Is it okay if someone helps me with this error inside of my project solution. What is a proper explanation as to why this error occurs."Markus
namespace WebAPI_DI
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register); //Errror code!
}
}
All-Star
53751 Points
24069 Posts
Re: Application Start error.
Dec 04, 2019 12:41 AM|mgebhard|LINK
What is the error? Can you share the WebApiConfig class?
All-Star
48740 Points
18193 Posts
Re: Application Start error.
Dec 04, 2019 10:09 AM|PatriceSc|LINK
Hi,
Always tell what actually happens rather than just that "it doesn't work". Error messages are intended to tell you (and us) what goes wrong rather than having to guess.
I'm not even sure if you mean this is a runtime error rather than a compile time error. It could be anything that causes this line to fail including this WebApiConfig class to be not declared at all or not properly ???)
Member
251 Points
423 Posts
Re: Application Start error.
Dec 04, 2019 04:10 PM|Markus33|LINK
Here is the Error! gebhard
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'WebApiConfig' does not exist in the current context WebAPI-DI V:\ETC Projects\Dependency Injection for Web API Controllers\C#\WebAPI-DI\Global.asax.cs 14 Active
Member
251 Points
423 Posts
Re: Application Start error.
Dec 04, 2019 04:11 PM|Markus33|LINK
It is a compile time error! patriceSc.
Member
251 Points
423 Posts
Re: Application Start error.
Dec 04, 2019 04:12 PM|Markus33|LINK
WebApp.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ProductsContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=ProductsContext; Integrated Security=True; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings></appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
All-Star
48740 Points
18193 Posts
Re: Application Start error.
Dec 04, 2019 04:21 PM|PatriceSc|LINK
It is the https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0103 error I suspected.
Make sure it is declared. Or this class is declared in a namespace which is not in scope (missing a "using" ?)
All-Star
53751 Points
24069 Posts
Re: Application Start error.
Dec 04, 2019 04:36 PM|mgebhard|LINK
The compiler error is telling you the compiler cannot find WebApiConfig.Register. Usually this is due to a missing "using" statement at the top of the file (Global.asax.cs). Place your cursor over the error, Visual Studio should pop up a help window that displays a list of possible fixes including adding the "using" line.
There can be other issue with your code. Unfortunately, you did not share the WebApiConfig.cs file so we cannot see if the namespaces match. The standard Visual Studio templates add this configuration automatically. Are you trying to configure Web API by hand? If so, create a new project and review the template code. Compare the template code to your code.
Member
251 Points
423 Posts
Re: Application Start error.
Dec 04, 2019 09:32 PM|Markus33|LINK
gebhard, i am happy to say that i fixed the error in the Api project. It was the WebApiConfig file. I was trying to hand build it so that why it failed. But when i compared the code i could see what to do to resolve the issue thanks. Markus.