Coder Social home page Coder Social logo

Compilation error in vs2022 about mradvice HOT 9 OPEN

hzzcmaj7 avatar hzzcmaj7 commented on September 25, 2024
Compilation error in vs2022

from mradvice.

Comments (9)

picrap avatar picrap commented on September 25, 2024

Could you upgrade to 2.15? There is an update to support more PDB (debug info) file formats.

from mradvice.

hzzcmaj7 avatar hzzcmaj7 commented on September 25, 2024

hi picrap,

Thanks.
The current solution compilation does not pass. How can I view valid information from the PDB, because there is an error in compilation and the project cannot be started.

I have tried upgrading to version 2.15.0, but the error message is the same. In addition, I have a new discovery that the solution has created many class library projects, each library project has already referenced MrAdvice, but only one of them has a compilation error. I tried to remove the reference of the error project to MrAdvice, and the compilation passed. However, I did not find any difference in this class library project. I also created a new class library project and copied the files from the previous project into the new project. The new project also compiled an error, I guess, may some code in this project have had an impact? I don't know where to start dealing with this issue.

from mradvice.

picrap avatar picrap commented on September 25, 2024

Could you build in verbose mode and give me more details about the error?

from mradvice.

hzzcmaj7 avatar hzzcmaj7 commented on September 25, 2024

hi picrap,

Thanks.
I have found the following information and I am not sure if it is helpful for troubleshooting,

5>MrAdvice 2.15+c60086a4a967e33b58ed9c2dd7854a934aa67d8c/.NET 6.0 weaved module 'MyPorjectName.ServicesNew, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' (targeting framework .NET 6.0) in 451ms
5>Unhandled exception: dnlib.DotNet.Writer.ModuleWriterException: Expected a null constant. Error occurred after metadata event BeginWriteMethodBodies.
5> at dnlib.DotNet.DummyLogger.Log(Object sender, LoggerEvent loggerEvent, String format, Object[] args)
5> at dnlib.DotNet.Writer.ModuleWriterBase.dnlib.DotNet.ILogger.Log(Object sender, LoggerEvent loggerEvent, String format, Object[] args)
5> at dnlib.DotNet.Writer.Metadata.Error(String message, Object[] args)
5> at dnlib.DotNet.Writer.Metadata.dnlib.DotNet.Writer.IWriterError.Error(String message)
5> at dnlib.DotNet.Pdb.Portable.LocalConstantSigBlobWriter.Write(DataWriter writer, TypeSig type, Object value)
5> at dnlib.DotNet.Pdb.Portable.LocalConstantSigBlobWriter.Write(IWriterError helper, Metadata systemMetadata, DataWriter writer, TypeSig type, Object value)
5> at dnlib.DotNet.Writer.Metadata.AddLocalConstant(PdbConstant constant)
5> at dnlib.DotNet.Writer.Metadata.WriteMethodBodies()
5> at dnlib.DotNet.Writer.Metadata.Create()
5> at dnlib.DotNet.Writer.Metadata.CreateTables()
5> at dnlib.DotNet.Writer.ModuleWriter.WriteImpl()
5> at dnlib.DotNet.Writer.ModuleWriterBase.Write(Stream dest)
5> at dnlib.DotNet.Writer.ModuleWriterBase.Write(String fileName)
5> at dnlib.DotNet.ModuleDef.Write(String filename, ModuleWriterOptions options)
5> at StitcherBoy.Reflection.ModuleManager.WriteModule(ModuleWriterOptionsBase moduleWriterOptionsBase)
5> at StitcherBoy.Reflection.ModuleManager.Write(String assemblyOriginatorKeyFile)
5> at StitcherBoy.Weaving.Build.AssemblyStitcher.Process(IDictionary`2 parameters, String entryAssemblyPath)
5> at StitcherBoy.Stitcher.Run[TStitcher](String[] args)

from mradvice.

picrap avatar picrap commented on September 25, 2024

Could disable advices injections and reenable them one by one until it breaks again? There may be a weaving error in a very specific context that we need to isolate.

from mradvice.

hzzcmaj7 avatar hzzcmaj7 commented on September 25, 2024

hi picrap,
Thanks,
I think this is a great suggestion. I have located the code below and commented it out, then it can be compiled successfully. However, I don't understand why they have an impact. Also, do I need to implement the commented part of the code in a different way?

public List GetAllCacheKeys()
{
//const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
//var coherentState = _memoryCache.GetType().GetField("_coherentState", flags);
//var entries = coherentState.GetType().GetField("_entries", flags).GetValue(coherentState);
//var cacheItems = entries as IDictionary;
var keys = new List();
//if (cacheItems == null) return keys;
//foreach (DictionaryEntry cacheItem in cacheItems)
//{
// keys.Add(cacheItem.Key.ToString());
//}
return keys;
}

from mradvice.

picrap avatar picrap commented on September 25, 2024

What advices do you apply in this assembly? Is this at assembly level? Or type/method level?
And in what chain is this code applied? In an advice or in some other code?

from mradvice.

hzzcmaj7 avatar hzzcmaj7 commented on September 25, 2024

hi picrap,
Thanks.
I followed the steps below to reproduce this compilation error,

Create a new class library project, reference MrAdvice(2.15.0), create a class and method with the following line of code, compile it, and the issue is reproduced,

public class TestService
{
public void Test()
{
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
}
}

Then I removed the const keyword and the compilation was successful. I think it's because of const. This is code written by someone else, and I don't know what their intention is. Also, I would like to know why const affects the compilation process of MrAdvice. Additionally, I found that this error only occurs when the const keyword is used internally within a method, but declaring a const constant at the class level does not result in this error.

Thank you very much.

from mradvice.

picrap avatar picrap commented on September 25, 2024

Nice! I’ll look at it.

from mradvice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.