blipson89 / Synthesis

Synthesis is a universal object mapper for Sitecore
MIT License
75 stars 25 forks source link

[BUG] Synthesis tries to call Sitecore.UsedImplicitlyAttribute which is deprecated #104

Closed NCHANL closed 2 years ago

NCHANL commented 2 years ago

Hi, I am upgrading Sitecore and Synthesis to Synthesis 9.1.4 with Sitecore 10.0.2, and when the project is deployed I get a "Sitecore.UsedImplicitlyAttribute does not exist in Sitecore.Kernel" error. Synthesis is not supposed to use that method, as it has been deprecated. I have tried to downgrade Synthesis to 9.1.0.2, and run Synthesis without any custom code, but I still get the same error. I do not have any "UsedImplicitly"/"UsedImplicitlyAttribute" calls in my code. If I remove the Synthesis.Startup.config and the Synthesis.ControlPanel.config, then there is no error, in the way that I can access Sitecore, but I still cannot access /synthesis.aspx.

Here is the stacktrace:

[TypeLoadException: Could not load type 'Sitecore.UsedImplicitlyAttribute' from assembly 'Sitecore.Kernel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=null'.] System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr typeInstArgs, Int32 typeInstCount, IntPtr methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +197 System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +166 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +156 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +612 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) +209 Synthesis.Utility.TypeCollectionUtility.WithAttribute(IEnumerable'1 types) +210 Synthesis.Synchronization.SynchronizationEngine.get_ModelDictionary() +94 Synthesis.Synchronization.SynchronizationEngine.AreTemplatesSynchronized() +339 Synthesis.<>c__DisplayClass1_0.b__0(IProviderConfiguration configuration, TemplateGenerationMetadata metadata) +62 Synthesis.SynthesisHelper.ExecMetadataWithAutoFriending(IEnumerable`1 configurations, Action'2 processAction) +523 Synthesis.SynthesisHelper.CheckSyncAll() +186 Synthesis.Pipelines.Initialize.CheckModelSynchronization.DoLogSync() +44 (Object , Object ) +9 Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +490 Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +236 Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22 Sitecore.Nexus.Web.HttpModule.Application_Start() +215 Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +1221 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +587 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +255 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +347

[HttpException (0x80004005): Could not load type 'Sitecore.UsedImplicitlyAttribute' from assembly 'Sitecore.Kernel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=null'.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737

Thanks in advance.

blipson89 commented 2 years ago

I'll take a peek tonight. Sitecore 10.0.2 or Sitecore 10.2?

NCHANL commented 2 years ago

Thank you! It's Sitecore 10.0.2.

blipson89 commented 2 years ago

Hi @NCHANL

Synthesis doesn't actually use the UsedImplictly attribute. This sounds incredibly familiar though, but I can't remember why.

Could you please check the following:

  1. Check your solution for UsedImplicitly. Maybe there's an older model or something with that attribute on it?
  2. Make sure all the dlls in your bin folder are for the correct version of Sitecore.
    • I strongly suspect you're going to find a Sitecore dll for the wrong version in your site's bin directory.

I've attached an XML file (Sitecore.Assemblies.Platform.txt) that contains the official Sitecore file versions for 10.0.2. If you run the following powershell script (update the two variables at the top) it'll tell you if your bin folder is clean:

$targetsFile = 'C:\PATH\TO\Sitecore.Assemblies.Platform.txt' #CHANGE ME
$binFolder = 'C:\inetpub\wwwroot\MYSITECOREINSTANCE\bin' #CHANGE ME

$foundMismatch = $false
$xml = Select-Xml -Path $targetsFile -XPath "/Project/ItemGroup/SitecoreAssemblies"
$xml | %{
    $officialVersion = $_.Node.FileVersion
    $dllName = $_.Node.Name
    if(!(Test-Path "$binFolder\$dllName")) {
        Write-Error "Missing File '$dllName'"
    } else {

        $dll = Get-Item -Path "$binFolder\$dllName"
        if ($dll.VersionInfo.FileVersion -ne $officialVersion) {
            Write-Error "Version Mismatch for '$dllName'. Expected: '$officialVersion', Found: '$($dll.VersionInfo.FileVersion)'"
            $foundMismatch = $true
        }
    }
}

Write-Host -ForegroundColor Green "Done!"
if ($foundMismatch) {
    Write-Host -ForegroundColor Yellow "Some dlls in the bin directory do not match official versions"
} else {
    Write-Host -ForegroundColor Green "The bin directory matches official versions"
}
NCHANL commented 2 years ago

Hi @blipson89

Thanks for the script, it helped a lot. Unfortunately, I still get the same error after fixing the version on all the .dll's, and I do not use UsedImplicitly anywhere in my code.

Do you have any other ideas as to what it may be?

Thanks in advance.

blipson89 commented 2 years ago

Hmmm. What version of Sitecore and Synthesis are you upgrading from? What other modules do you have installed other than Synthesis?

NCHANL commented 2 years ago

I am upgrading from Sitecore 9.0 to 10.0.2, and from Synthesis 9.0.1 to now 9.1.5. I am also using Unicorn (4.1.3) and Solr (8.4.0).

It worked before I started upgrading Sitecore, so maybe there are some modules that Synthesis started/stopped using that are causing these issues?

It is specifically from the Synthesis.Startup.config, and the Synthesis.ControlPanel.config that these problems occur, maybe they are calling an external module, where I have the wrong version?

blipson89 commented 2 years ago

Synthesis 9.1.5 is built against Sitecore 9 DLLs. The parts of the Sitecore API that Synthesis uses are really low-level and don't tend to change much between Sitecore versions, so every time Sitecore comes out with a new version, I test Synthesis against the newest version of Sitecore.

I've tested Synthesis against Sitecore 10.0.0 through 10.1.0. It's possible that maybe its interacting with something in your solution in a way that didn't break on my local.

What we can try is recompiling Synthesis against the Sitecore 10.0.2 dlls and seeing if that fixes the problem. Unfortunately, I won't be able to get to this until tomorrow evening. Once I've done that, I'll attach the updated NuGet packages to this ticket.

If you'd like to try this sooner, you can pull down the repo and try updating it.

blipson89 commented 2 years ago

Unicorn 4.1.3 has the UsedImplictly attribute in it. It was removed in 4.1.6 (https://github.com/SitecoreUnicorn/Unicorn/issues/416)

While Synthesis is the one throwing the error, it's not the source. Could you try updating Unicorn to 4.1.6 or higher?

NCHANL commented 2 years ago

Thank you so much, that worked! I updated Unicorn to 4.1.6 and now the error is gone.

blipson89 commented 2 years ago

Glad I could help!