1

In a Visual Studio (Professional 2017) solution, I have multiple projects, two of which are startup projects, the UI and the API. The curious thing is that the API\Global.asax.cs does not seem to be executed, although both startup projects are actually enabled to be launched for debugging. I am sure about that, since when hitting the green Debug arrow, two browser windows open, and both UI and API work.

There are two distinct Global.asax.cs-files, one for each startup project (whether that is a sensible design, I don't know - I took over the solution this way). Within the one for the API, breakpoints are not working, more specifically VS says:

The breakpoint will not currently be hit. A copy of Global.asax.cs was found in UI.dll, but the current source code is different from the version built into UI.dll.

To allow this breakpoint to be hit: right-click on the breakpoint, choose either 'Conditions...' or 'Setting...'. Then chcoose 'Location', 'Allow the source code to be different from the original.'

To allow this for all breakpoints, disable the option 'Required source files to exactly match the original version' under Tools, Options, Debugging, General.

The full hover-over-breakpoint-message looks as follows: full error message screen shot

Following the last suggestion did not change anything. Concerning the first suggestion, I do not have the options to choose in the context menu under Conditions.

I cannot inquire to much about the solutions's architectural background, that is why I am asking here for help: I am assuming that the error message also means that the file API/Global.asax.cs is not read at all, or is that conclusion wrong?

More importantly: How do I ensure that API\Global.asax.cs is read/ executed? Differently put: When is it supposed to be executed when in debug mode? I have the impression, it executed every now and then since I see debug-output in my VS-Output window sometimes - I did not manage to guess when it is executed.

Edit: Further Background

In in the Solution Property Pages (right-click on the solution and choose Properties), there is the option Multiple startup projects chosen. The API project is in the list before UI.

Under Project Dependency is specified that the API project depends on different other projects, but not the UI project. The other projects have some inter-dependencies as well, but none of them depends on the UI project. The UI project does not depend on any other project, either.

References

Community
  • 1
  • 1
B--rian
  • 5,578
  • 10
  • 38
  • 89

1 Answers1

2

In any one ASP.NET web app there can be only one Global.asax file (whether with code behind or not). One of the Global.asax files will be overwriting the other if both projects deployed to the same folder, and the one that wins will specify the winning start up type that hooks into the Application instance's events:

 <%@ Application Codebehind="Global.asax.cs" Inherits="MyProject.MvcApplication" Language="C#" %>

The only way to have two would be two separate web apps (one could be in a child folder, providing it is – in IIS – set as a web app of its own and thus running it its own AppDomain if in the same IIS App Pool or otherwise in its own process).

Richard
  • 106,783
  • 21
  • 203
  • 265
  • For me, one`Global.asax` is in `API/`, the other in the subfolder `UI/`, no one is in the main folder, so it is not immediately clear which is the parent. I have the impression that the UI-one wins since it the one started second. Does that make sense? Where and how do I specify the parent if I cannot move the two files (I was told, I am not allowed to move them)? – B--rian Jan 15 '20 at 14:54
  • Are the two folders just folders/virtual directories in IIS, or separate web apps. pulling the `global.asax` anywhere other than the root of the web app isn't normal. – Richard Jan 15 '20 at 14:58
  • I guess I am not familiar with the exact definition of Web App in this context (I assume it is different from VS project). In my main folder of the solution, I have the solution file `*.sln` (and `packages.lock.json`), then there are several folders for the projects. For deploying, we end up with two folders only, one for each startup project. – B--rian Jan 15 '20 at 15:05
  • If it helps, the API is fully C#, the UI is in React. Both folders have their own `favicon.ico`. The `UI/global.asax` is mainly empty, except for a `protected void Application_Start(object sender, EventArgs e) { RouteConfig.RegisterRoutes(RouteTable.Routes); }` - the one of the API has quite some stuff inside `Application_Start()`. – B--rian Jan 15 '20 at 15:07
  • So when deployed, each is in a separate folder, inside the same parent? Does that parent contain anything asp.net related? or its parent? How are these set up in IIS? Is one nested inside the other? Inside a common parent? Is that parent an asp.net thing? –  Jan 15 '20 at 15:12
  • @Amy: When deployed, there are two different folders `UI` and `API`, same parent, but in the parent is nothing else than the two folder. Concerning the IIS-setup - what do you refer to? What should I check? – B--rian Jan 15 '20 at 15:20
  • Please note my edit on the project dependency in the question. I assume that I have two web-apps, the `API` and the `UI`. Do you agree? – B--rian Jan 15 '20 at 15:22
  • IIS has its concept of an App that is significant here (hence needing to know that). I learnt in the days before IIS Express which hides many details from devs until the point of deployment. For something else please ask a new question (the purpose of [SO] is for others to be able to find solutions to their similar problems). – Richard Jan 15 '20 at 15:45