I have a C#.NET class library, ClassLib
, which uses both Newtonsoft.Json
and RestSharp
.
The idea of the library is that it is an API "super-wrapper" that is included in third-party end-user applications, eg desktop apps, web apps, Windows services, etc.
In order to keep things self-contained, I've embedded Newtonsoft and RestSharp in ClassLib using the embedded resources and AssemblyResolve approach discussed in several threads on SO.
So far, so banal; I've used this approach several times in different projects such as plug-ins and everything generally works as expected.
This time, however, I've hit a weird snag. And it's inconsistent.
I use ClassLib in a couple of small desktop app projects which demonstrate ClassLib's capabilities as well as a main production project.
Everything works perfectly in the demo projects, and was working fine in the production project. But the production project has just started throwing an assembly not found error:
"Could not load file or assembly 'RestSharp, Version=100.0.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75' or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500)":"RestSharp, Version=100.0.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75"
I've tried to get the demo project to throw this error by running it with ClassLib.dll on four other machines which don't have RestSharp registered anywhere I can find but it runs perfectly.
But no matter what I do with the production project - which is running on a machine where there are multiple extraneous copies of RestSharp but nothing in the GAC that I can find - it continues to fail on this error.
The thing is, though, it was fine until yesterday.
So, of course, something has changed somewhere to create the issue, I just don't know what it is.
Pertinent points:
- ClassLib is obfuscated using Obfuscar. This has always been the case and nothing (that I can pinpoint) has changed.
- ClassLib, the demo projects and the production project all target .NET 4.5, as do the NuGet Newtonsoft and RestSharp packages.
- Everything builds fine; the error is run-time on first call to the API.
- If I include RestSharp as a reference assembly in the production project, all is well.
- I've double-checked assembly versions all over the place.
- I've cleared caches and even opened the project in other versions of VS (I use VS2017 Community but was using VS 2013 Pro until recently).
- Yes, I realize I could simply include RestSharp as a ClassLib dependency but I'm reticent to do that given that the embedded approach should work fine.
- I've also tried using Costura - which seems to work really well as far as I can tell - but the symptoms are the same.
Any ideas?