oleksabor / nlog.indentexception

custom NLog layoutRenderer allows to show exception using readable format (from my point of view) in the log (file or console). Additionally it does not log full exception stack trace if it is logged second time (it happens if exception is rethrown like inner exception)
MIT License
3 stars 1 forks source link

Could not load file or assembly NLog.IndentException #3

Closed mr-j0nes closed 8 months ago

mr-j0nes commented 8 months ago

Hi,

this is not actually and issue but a crying for help.

I am new to .NET and I do not seem to understand how to make this library work. I have installed nlog and nlog.indentexception as NuGet packages in one of the projects (I have multiple projects) within my solution. I have installed these on the main project and used nlog as reference in the other projects.

In the nlog.config I have added following snippet from your example:

    <extensions>
        <add assembly="nlog.IndentException"/>
    </extensions>

Then when running my program I get following exception in the nlog internal log file:

2024-01-03 08:43:10.8939 Warn Error has been raised. Exception: NLog.NLogConfigurationException: Error loading extensions: NLog.IndentException
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'NLog.IndentException, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'NLog.IndentException, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
   at System.Reflection.Assembly.Load(String assemblyString)
   at NLog.Config.AssemblyExtensionLoader.LoadAssemblyFromName(String assemblyName)
   at NLog.Config.AssemblyExtensionLoader.LoadAssemblyFromName(ConfigurationItemFactory factory, String assemblyName, String itemNamePrefix)
   at NLog.Config.LoggingConfigurationParser.ParseExtensionWithAssemblyName(String assemblyName, String prefix)
   --- End of inner exception stack trace ---

As I understand the assembly="nlog.IndentException" bit searches for a dll called that way? I do not seem to find any dll with that name in the build folder (I do find an nlog.dll though)

The versions I used are: NLog (5.2.8) NLog.IndentException (0.1.9)

Thanks in advance.

oleksabor commented 8 months ago

Hello

Please check how you have added projects references to the nlog.IndentException.

You have use package reference for each project where nlog.IndentException is used.

But as soon as nlog.IndentException should not be used from any project directly the first step I would like to ask you to do is

Remove all nlog.IndentException (as package or dll) references from all projects (except the main project in solution).

The idea is to copy if newer nlog.IndentException to the binary folder. Please check property page for nlog.IndentException reference in the main project and adjust Copy to output directory with copy always value.

mr-j0nes commented 8 months ago

Thank you for the reply. I have done as you suggested but I still get the error "Error loading extensions: nlog.IndentException"

Here the properties of my main project (including the new changes):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NLog" Version="5.2.8" />
    <PackageReference Include="NLog.IndentException" Version="0.1.9" >
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\ApiWrapper\ApiWrapper.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="NLog.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>
oleksabor commented 8 months ago

It took some time for me to get back to the package.

Please check sample folder.

No .dll is created within the package. The package contains .pp files compiled into the assembly when NLog.IndentException package is referenced.

please use your project assembly name within add assembly extension configuration.

    <extensions>
        <add assembly="nlog.identtest"/>
    </extensions>
mr-j0nes commented 8 months ago

Thank you very much. Now I could make it work. I wasn't realizing that the name of the assembly was the one where the nlog.IndentException package was compiled into. After I changed this it worked.

oleksabor commented 8 months ago

Well, Test project has the nlog.IndentException assembly name in the nlog.config actually. This may cause misunderstanding.

I'v put a sample project already but I have a plan to add a few words about how it works in the readme a little bit later.

On Tue, Jan 9, 2024 at 6:42 PM mr-j0nes @.***> wrote:

Thank you very much. Now I could make it work. I wasn't realizing that the name of the assembly was the one where the nlog.IndentException package was compiled into. After I changed this it worked.

— Reply to this email directly, view it on GitHub https://github.com/oleksabor/nlog.indentexception/issues/3#issuecomment-1883401276, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3QIWYJ6FLPEY6DIXAPCS3YNVXPTAVCNFSM6AAAAABBLBKZBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBTGQYDCMRXGY . You are receiving this because you modified the open/close state.Message ID: @.***>