3

My question is regarding handling errors like "missing an assembly reference?" in views specifically layout.cshtml

e.g. if I have some code in Head tag in layout.cshtml

<head>

@{
  @{

        try
        {
            var EnableSomething = BusinessLogic.MyBLL.GetSetting("SettingName");
        }
        catch { }
    }
}

</head>

This will work properly, but what if someone came and change "MyBLL" to "MyBLL1", in Layout.cshtml or remove the BusinessLogic DLL or change the DLL in a way that "MyBLL" does not exist in that DLL.

If there a way to handle this kind of situation in layout.cshtml itself ? I know this is a strange situation but just wanted to know if there is any way to handle this kind of situation.

Thank you all.

7
  • 1
    That code belongs in your controller, not a view. Commented Jan 26, 2018 at 6:47
  • MyBLL is class? BusinessLogic is namespace? Commented Jan 26, 2018 at 6:54
  • @StephenMuecke you are right, this code should be in controller but in this case it is in view ( layout.cshtml ). and it gives the compilation error when anyone request the page in above situation. Commented Jan 26, 2018 at 6:54
  • @daniel.shih yes, that is correct. Commented Jan 26, 2018 at 7:05
  • 1
    @Deepak you already know what your problem is. The code is, where it should not be. Move it and get compile time errors. Pass the information into the view using a viewmodel or ViewData Commented Jan 26, 2018 at 7:17

1 Answer 1

1

You could try and install the Nuget of RazorGenerator

It will cause the build to break if building a view fails , So in the case of "MyBLL" to "MyBLL1"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.