Microsoft.AspNet.Mvc.Core.pdb not loaded - debugging

I have a ASP.NET 5 , MVC 6 project which has reference to a CL in the same solution.
When I try to debug I am unable to enter to the CL's breakpoints.
When I come to the function calling the CL and hit F11 it just continues , so it doesn't enter into the function for debug.
When I debug and get over to the function of the CL and choose "Step into specific" and choose the function it says :
Microsoft.AspNet.Mvc.Core.pdb not loaded.
Microsoft.AspNet.Mvc.Core.pdb contains the debug information required to find the source for the module Microsoft.AspNet.Mvc.Core.dll
Module Information
Version : 6.00.0.10417
Original Location : <path in local disk>
Try one of the following options :
Change existing PDB and binary search paths and retry:
Microsoft Symbbol Servers
So when I try to get it load from microsoft symbol server it says :
Microsoft.AspNet.Mvc.Core.pdb could not be found in the selected paths
My main project is in MVC 6 and my dll is target framework : .Net 4.5.2

I think that due to the beta nature the pdb files are not on the symbol servers. I would assume that after RTM (remember VS is RC but asp.net 5 is very much still beta) they would be added to the symbol servers.
If you need support before that you can clone the asp.net MVC repository (https://github.com/aspnet/Mvc.git) to a location outside your project. Then in the global.json (solution level file) add that path to the project property. This will instruct the compiler to look there for dependency resolution. The compiler will always attempt to resolve dependency using local source over nuget package. In Visual Studio right click on references > restore packages. You should see the package icon change to indicate source. Then you can simply build, and step directly into the source.

This error can be occurred because of a wrong doing in code. I got this error once where I was implementing a base class and overriding its method without a base method call where my db context was initialized. But in my controller I was trying to use the db context which is still not initialized which caused a null reference error. Once I fixed it this error disappeared.
public class MyController : BaseController
{
private MyService _myService;
protected override void Initialize(RequestContext requestContext)
{
//I missed the base call here
//base.Initialize(requestContext);
_myService = new MyService(myDbContext);
}
}
public class BaseController : Controller
{
public MyDbContext myDbContext { get; set; }
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
myDbContext = HttpContext.GetOwinContext().Get<MongoDbContext>();
}
}

Try deleting the bin folder and rebuilding the solution.

Related

How to send a form/notification to user from a DLL?

I have a DLL .
And want to send a form/notification to user( who would reference my dll) from this dll.
I just want to build a function inside one class in my dll such that ->, once a user runs his local program and references my dll -> and calls a function that is present in dll -> that particular function should show up a form/notification to user ( from some functionalities in dll )? Is there any other method for the same?
I tried converting the library to a Winform from class library type and that would change its properties into an executable and it would demand presence of the main function. But I am just building a library that can be referenced and when called by the user produces a form at their end?
I tried toast notifications but not .show() method doesnt work inside new ToastContentBuilder() while i call that in a fucntion from my library . Otherwise as an idenpendant console app , it worked fine
Is there a way I can have a project for toast notification in the same solution as that of my library and then call from a class in my main library -> the function present in this different project for toast notif and would produce the toast notification.
You can try the following steps to send a notification to the user from the dll.
First, please create a class library(Target Framework is .NET Core 3.1) called TestDll.
Second, you could install the nuget-package Microsoft.Toolkit.Uwp.Notifications in the class library.
Third, you can add a class and refer to the following code example.
namespace TestDll
{
public class Example
{
public void Setnotifications()
{
new ToastContentBuilder().AddArgument("action", "viewConversation")
.AddArgument("conversationId", 9813)
.AddText("Ev2 Compiler Library")
.AddText("Allow sending build Data to Microsoft")
.AddButton(new ToastButton()
.SetContent("Yes")
.AddArgument("action", "reply")
.SetBackgroundActivation())
.AddButton(new ToastButton()
.SetContent("No")
.AddArgument("action", "like")
.SetBackgroundActivation())
.SetToastScenario(ToastScenario.Reminder)
.Show();
}
}
}
Fourth, please rebuild the class lib and create a console app(Target Framework is .NET Core 3.1).
Fifth, we can add the project reference TestDll to the console app and write the following example in the main method.
static void Main(string[] args)
{
Example example = new Example();
example.Setnotifications();
}
Finally, we can see the notification in the right bottom of computer like the following:
Besides, the problem about 'toast notifications but not .show() method' maybe that you used .net standard framework, you can solve the problem by changing to the .net core framwork.

Unbound breakpoints when debugging in Blazor Webassembly when using certain attributes/classes

I'm developing a modular blazor application (5.0.2) using VS 2019 (16.8.4), which is structured as follows:
a "Main" Solution, which consists of
RCL
Wasm project to startup the application
several "Sub" solutions which reference the Main RCL (Base components, etc) which consist of
.net5 libraries (Models, Web-service access, etc)
RCL with components, referencing the .net5 libraries (via project reference)
All projects have a post-build event to copy the DLL and PDB files to a certain path, e.g. D:\TMP.
The SubSolution references the MainRCL library via this path.
The Main Wasm project references the SubRCL library also via this path (for adding services at startup/Program.cs).
The MainRCL does not have a reference to SubRCL (components are rendered via reflection/BuildRenderTree() according to configurable UI definition).
Debugging the Main Solution worked perfectly (IIS Express/Application Debugging).
Then I tried to debug the SubModules -> I started debugging from the MainSolution and opened files from the SubModules projects in this VS instance.
At some libraries, debugging was working, but not for the SubRCL ("Unbound Breakpoint"). Then I was able to reproduce the (very strange) issue with sample solutions:
The "MainRCL" provides 2 Attributes:
[AttributeUsage(AttributeTargets.Class)]
public sealed class TestNoEnumAttribute : Attribute
{
public string Name { get; set; }
public string Mode { get; set; }
public TestNoEnumAttribute(string name, string mode)
{
Name = name;
Mode = mode;
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class TestEnumAttribute : Attribute
{
public string Name { get; set; }
public EventExecutionMode Mode { get; set; }
public TestEnumAttribute(string name, EventExecutionMode mode)
{
Name = name;
Mode = mode;
}
}
public enum EventExecutionMode
{
AutomaticAll = 0,
ManualConfiguration = 2
}
The SubRCL uses these attributes at a test-method:
[TestNoEnum("Test", "EventExecutionMode.ManualConfiguration")]
//[TestEnum("Test", EventExecutionMode.ManualConfiguration)]
public class Module1Test
{
public int IncreaseNum(int num)
{
var x = new Part1();
var part1Num = x.DoStuff(num);
var newNum = part1Num + 1;
return newNum;
}
}
The class "Part1()" which is called, is located at another library of the SubSolution
The breakpoint at the "DoStuff()" method in Part1 class is always hit (in separate .net5 library).
The breakpoint at the "IncreaseNum()" method is only called when the [TestEnum] attribute is NOT used.
As soon as the [TestEnum] attribute is used, there is an "Unbound Breapoint"; the breakpoint in "DoStuff()" method in another library is still hit.
Then I tried to "add existing project" to SubSolution and added the MainWasm project and started debugging directly from SubSolution -> same behavior.
Is there anything I oversee (e.g. regarding DLL-references or PDB file copy)?
This is already my second approach of trying to debug these modular-structured solutions - first I tried to debug via IIS (How to debug Blazor Webassembly on IIS with VS by attaching to Chrome?), but this was also not successful.
Found out there is an issue with debugging when using attribues with enum parameters:
https://github.com/dotnet/aspnetcore/issues/25380
-> I replaced the enum parameters and debugging is working fine now - Didn't get any feedback when this will be fixed so far
I had the same issue with my Blazor WASM not able to be debugged in VS due to 'Unbound breakpoint'. I have multiple projects running under the same solution and while initially the debugging worked for the WASM, it stopped after a while.
Eventually I was able to find a work around by waiting until all projects loaded and then I could disable the 'Unbound' breakpoint and re-select it. It then worked as expected.
It's not an ideal solution (especially if you have multiple breakpoints while troubleshooting) but it is workable.
I had this problem in .NET 6 and Visual Studio 2022.
I made a codebehind-file component.razor.cs but I also had code in the razor-file itself. Moving the code to the codebehind-file solved the issue and enabled the breakpoints.

Referenced .Net assembly not found at runtime

Here's the scenario.
I created a brand new Asp.Net DNX RC2 Final project. I also added a .Net class library project to my solution (both under FX 4.6.1). The class library project is located in the src folder.
Then, I add a reference to the class library, and it can successfully restore all packages after making changes to the project.json file.
I've added a simple foo function to my class library
namespace ClassLibrary1
{
public class Class1
{
public static string Foo()
{
return "Bar";
}
}
}
and finally in my Home/Index view, I have added the following on top
<div>
#(ClassLibrary1.Class1.Foo())
</div>
The solution compiles with no errors.
You may think so far so good, let's continue.
Then, when I run the solution, the following is shows:
At runtime, my class library is not available.
I ran into a similar situation. In my case I got a RazorEngine exception in Visual Studio which at least gave me an indication of what was going on (it was something like a missing reference exception, even though the class library was added as a reference).
The only way that I could get it working (I'm hoping there is a better way), was to add the following code to my ConfigureServices method in Startup.cs:
services.Configure<RazorViewEngineOptions>(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = (context) =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(MetadataReference.CreateFromFile(typeof(ClassLibrary1.Class1).Assembly.Location));
};
});
I got the idea from the following websites:
Callback on RazorViewEngineOptions
Configure RazorViewEngine
I did confirm that your example is working when I add the code mentioned above.

Strange MethodMissingException

I have stumbled upon interesting problem which is destroying me last couple of hours. I have project in VS, in references I have library Communication.dll, which contains class Service.
I am invoking following method:
public void ConnectPipe()
{
Service service = new Service();
service.ConnectionMode = ConnectionModes.PIPE;
service.Connect();
}
when I run it, on second line I get MissingMethodException - Method not found: 'Void Service.set_ConnectionMode()'
when I press F12 on service class, I get the Assembly info for the class. When I look for my property, setter is in place, so it does not look like problem with referenced library:
public ConnectionModes ConnectionMode { get; set; }
has anyone any idea where problem might be please?
Had the same issue. Fixed by updating reference to the library.
Point to the exact file on the local, through button "Browse..." don't choose from the library list in references manager - that doesn't work correctly sometimes.
And rebuild the referenced assembly.

Ninject + MVC3 = InvalidOperationException: Sequence contains no elements

I created a new MVC3 project, hit F5, saw the sample page.
Then I used NuGet to get the Ninject.MVC extension. I modified my global.asax according to the Ninject documentation, How To Setup an MVC3 Application:
public class MvcApplication : NinjectHttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index",
id = UrlParameter.Optional });
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
Now when I run the app, I get the yellow screen of death with the following exception:
InvalidOperationException - Sequence contains no elements.
at System.Linq.Enumerable.Single(...)
at Ninject.Web.Mvc.Bootstrapper.Initialize(...)
line 67.
And sure enough, line 67 of that file calls .Single(), thus throwing the exception.
What am I doing wrong?
I have to add to this in the hopes that someone else will resolve the issue more quickly and not want to pull out every strand of hair on their head like I almost did.
I needed to rename everything in my project to match new business terms. I changed namespaces everywhere and I even changed the Assembly Name (right-click project > properties > application tab) so that the generated assembly matches the new naming convention. The assembly rename is what made Ninject very angry!
By renaming the assembly that gets generated a new file with the new name was being created when we compiled. However, the old file with the old name was still in the bin directory! If you have Ninject activating via the added class in App_Start then this activation class will get invoked in BOTH assemblies (old one AND new renamed one). Don't ask me how or why, but it does and it gives you this "already initialized" error.
Not even cleaning solution works because Visual Studio will only remove the binaries that it is generating, which would be the new renamed ones. It leaves the old ones alone just sitting there.
Go delete your bin folder before you try doing anything else! I hope this saves someone else from wasting valuable working hours!
You might notice that after installing the ninject.mvc3 NuGet there is an App_Start subfolder created inside your project containing an NinjectMVC3.cs file. Delete this folder and try again. So here are the steps I followed:
Create a new ASP.NET MVC 3 project using the default template
Bring up the Package Manager Console window (View -> Other Windows -> Package Manager Console)
Type install-package ninject.mvc3 on the command line
Replace the default code in Global.asax with the code in your question
Delete the AppStart subfolder created during the installation of the package
Run the application
Enjoy the beauty of the /Home/Index default page opened in your Google Chrome web browser :-)
I have updated the documentation Wiki linked in your question to show both ways to setup a MVC3 application. I suggest to use the second option which is the prefered way for theNuGetpackage.
Instead of deriving from NinjectHttpApplication it is using the NinjectMVC.cs in the AppStart folder which is created during installation of the package. This is also the location where you create the kernel and where you load your modules or where you define the bindings.
As Alex Ford said:
I have to add to this in the hopes that someone else will resolve the
issue more quickly and not want to pull out every strand of hair on
their head like I almost did.
I had a special version of that problem which could get solved as follows:
Exception Details: System.InvalidOperationException: Sequence contains no elements
This error is caused by the fact that there are 2 projects with
App_Start/NinjectWebCommon.cs
Removing the file eliminates the error.
Note: if you are nu-getting Ninject.Web.Common because you need to
reference Ninject.Web.Common assembly for one of your class library
project, you can safely remove the “App_Start” folder and
“NinjectWebCommon.cs”. It is meant for web/web api projects.
>click here to view the original blog entry<
My solution was that I had set the App_Start folder property, Namespace Provider to True.
I had changed this to False so that Resharper wouldn't highlight the namespace NOT matching the folder structure.
Wanted to add one more cause ...
We installed the Ninject.MVC3 package to multiple projects - only one of which was an actual MVC applicaiton. However, we forgot to remove the App_Start folder.
Removing the App_Start folder from the referenced project resolved the issue.
To tack on to #Chev's answer... this was my ultimate issue as well. If you're deploying to an Azure Website (now named AppSite), you want to click on this box in the publish to remove old files

Resources