0

I have the following scenario:

Solution

Where ProjectA is a simple class library, and ProjectB is a Console Application.

ProjectA.Class1.cs contains the following code:

using System;

namespace ProjectA
{
    public class Class1
    {
        public void A()
        {
            B();
        }

        [Weaver]
        public void B()
        {
            Console.WriteLine("I'm in B()");
        }
    }
}

ProjectA.Weaver.cs contains:

using MethodDecorator.Fody.Interfaces;
using System;
using System.Reflection;

namespace ProjectA
{
    class Weaver : Attribute, IMethodDecorator
    {
        public void Init(object instance, MethodBase method, object[] args)
        {
            Console.WriteLine("Initialising");
        }

        public void OnEntry()
        {
            Console.WriteLine("Entry");
        }

        public void OnException(Exception exception)
        {
            Console.WriteLine("Exception");
        }

        public void OnExit()
        {
            Console.WriteLine("Exit");
        }
    }
}

And the Console Application's (ProjectB.Program.cs)entry point contains:

using ProjectA;

namespace ProjectB
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new Class1();

            a.A();
        }
    }
}

And ProjectA.FodyWeavers.xml contains:

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
    <MethodDecorator></MethodDecorator>
</Weavers>

If I put a breakpoing inside Class1.A(), and attempt to Step-into (F11), the following Source Not Available window pops up:

Source Not Available

Is there a way to:

  • Prevent the debugger from attempting to step into the weaver
  • Tell the debugger where the source code for the weaver is

I've tried:

  • Enabling Just My Code
  • Adding Attributes to the Weaver.cs methods ([DebbugerNonUserCode], [DebbugerStepThrough], [DebbugerHidden]...)
  • Adding the Fody references to the ProjectB
  • Setting the project's Build Debugging Information to Full

Using:

  • Visual Studio 2019 Community Edition
  • .NET Framework 4.7.2
  • Fody 6.2.0
  • MethodDecorator.Fody 1.1.0
Nelladel
  • 166
  • 3
  • 12
  • Put break Point in `Init` and `B` functions and debugger will be paused. the `source not filed` is appeared, i think because you try to debug disassembly code not a c# code. – Mohammed Sajid Jun 14 '20 at 01:32

2 Answers2

0

As far as I know, the VS team, in fact, has not resolved this issue at this time. I've tried this myself and even disabling disassembly didn't fix it.

There is an extension for Visual Studios to disable the 'Source not available' window, but stepping into code would look like Visual Studio would just refuse to do it (unless you click a number of times until it reaches to the first method).

A thread in the Visual Studio Developer Community page is here.

The 'Disable No Source Available Tab' extension is here, for which you could also search it up in Visual Studio's by clicking on the Extensions tab, Manage Extensions, then search for 'Disable No Source Available Tab', then click Install.

Until Visual Studios does anything about it or there is a better extension, my suggestion would be to set a breakpoint deeper into the call stack (for example, setting the breakpoint at Init(object instance, MethodBase method, object[] args)).

JJtheJJpro
  • 81
  • 3
  • 7
0

A new version of the MethodDecorator weaver ( v. 1.1.1 ) has been released, which fixes this issue thanks to Tom Englert.

Link to the PR 254

Link to the issue raised in the GH page

Nelladel
  • 166
  • 3
  • 12