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.
    – user3559349
    Jan 26, 2018 at 6:47
  • MyBLL is class? BusinessLogic is namespace?
    – D-Shih
    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.
    – Deepak
    Jan 26, 2018 at 6:54
  • @daniel.shih yes, that is correct.
    – Deepak
    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
    – Marco
    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"

Not the answer you're looking for? Browse other questions tagged or ask your own question.