Could not load file or assembly 'CustomMarshalers.dll' while adding AssemblyReferences

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 11 months ago by BenjaminLopVic - France
Version: 24.1.2
Platform: .NET 4.8
Environment: Windows 11 (64-bit)
Avatar

Hello,

Since I switched PCs (not much has changed, same OS, same brand...), I've encountered an issue when attempting to add an assembly to my Syntax Editor. I'm getting this exception:

Could not load file or assembly 'CustomMarshalers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

This is how I load my assembly :

project.AssemblyReferences.Add("My.Custom.Assembly");

"My.Custom.Assembly" is an internal assembly installed with NuGet Package Manager and referenced in PackageReferences. This assembly works well when I use it directly in the project. However, when I try to initialize my SyntaxEditor with it, I encounter this exception.

Any help on this would be awesome.

Thanks,

Benjamin.

Comments (4)

Posted 11 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

That CustomMarshalers assembly must be required for your assembly.  When the exception occurs, do you see any inner exceptions that might give more of a hint on why it's not loading?  Generally if there are inner exceptions available, the innermost one will give the best information about the true problem.


Actipro Software Support

Posted 11 months ago by BenjaminLopVic - France
Avatar

Hello,

Unfortunately, there is no inner exception. However, I've attempted a few things:

  • Added a reference to CustomMarshalers and checked the "local copy" option => No change.
  • Added "project.AssemblyReferences.Add("CustomMarshalers");" before my assembly => No error, but still encountering errors with My.Custom.Assembly.
  • Manually added "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\CustomMarshalers.dll" to my bin folder => It worked!

Since CustomMarshalers is part of .NET 4.8, why do I have to copy it manually? I've added "mscorlib" to my AssemblyReferences, and I have no issues even if "mscorlib.dll" is not in my bin folder but in the "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8" folder.

Thank you,
Benjamin.

Posted 11 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The assembly load sequence for .NET Framework assemblies will follow these steps in order to try and locate the assembly:

  • Check in the app domain (if you've referenced and loaded it in your VS project).
  • Try to load it from the GAC via a call to Assembly.ReflectionOnlyLoad.
  • Try to load via probing in the application bin folder.

We haven't worked with the CustomMarshalers assembly before.  If is part of the .NET Framework, which it appears to be, I would have expected the second step to be able to locate it, but that method call throws a not found exception.  

Digging in deeper, it looks like CustomMarshalers might only be in the 32-bit GAC and perhaps that is why it's not located, whereas other .NET Framework assemblies are mainly in a more common MSIL GAC.  That's the only difference I can detect between CustomMarshalers and other assemblies.  Perhaps Microsoft's Assembly.ReflectionOnlyLoad code doesn't look at the 32-bit GAC.

You might have to continue doing your last workaround to handle this scenario.


Actipro Software Support

Answer - Posted 11 months ago by BenjaminLopVic - France
Avatar

Hello,

Thanks for your help.

After many tries, I think the problem comes from my application, but I don't know where. I created a new application with the same syntax editor and the same custom DLL, and it works well.

So, I added an after-build target in my csproj like this:

<Target Name="CopyCustomMarshalersDllAfterBuild" AfterTargets="PostBuildEvent">
	<Copy SourceFiles="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\CustomMarshalers.dll" DestinationFolder="$(TargetDir)" />
</Target>

Thanks again.

Benjamin.

The latest build of this product (v24.1.5) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.