[DevExpress Support Team: CLONED FROM S30927: Designers - Support multi level projects [Objects Library + Common module + WinForms Module + WinForms Application] and avoid the "Dictionary already contains class info" exception]
As I understand, no progress here after 8 years and Visual Studio 2015?
Questions regarding S30927
Answers
Hello Everyone,
Below is what I recommended to Baha'a Eldin Elsayed via email.
We suggest you ensure that projects in your XAF solution use project-to-project references instead of file assembly references. Microsoft recommends this as the best way to manage references in a project: https://docs.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2019#project-to-project-references. Our Model Editor requires project-to-project references to collect accurate dependency information. If projects inside your XAF solution are added as file references, it may not only increase maintenance costs, but also cause "Dictionary already contains ClassInfo. Possible reason: the assembly has been loaded twice" errors in the Model Editor.
We avoided this behavior in the new Model Editor for .NET Core and .NET Standard projects, which uses a different architecture and out-of-Visual Studio process. For more information, please review the following help topics:
Hello Ilja,
As noted in the original post, this behavior is caused by a Visual Studio issue and cannot be overcome on our side.
Would you please clarify whether you are dealing with the same error in your project? If so, would you please try three solutions described in the original thread? Let us know in case of any further questions.
Hi.
It's hard to say whether it's the same error or another because we patched the whole module/model mechanism a lot. I just hoped that you may have heard about this issue from other customers and know that it was fixed.
Anyway, in our case it was caused because Visual Studio somehow managed to load the same assembly twice from different locations: both from temp ProjectAssemblies and local output directories. And we've solved it by discarding in the design mode the first part of DevExpress.Persistent.Base.ReflectionHelper.CurrentDomain_AssemblyResolve method where he searched for assemblies in resolve paths, which turned out to be output directories. And now he uses only the assemblies loaded in current domain. And in our case they're already there. I understand that there might be some problems in the future but so far it works fine.
>>
It's hard to say whether it's the same error or another because we patched the whole module/model mechanism a lot.
<<
Thanks for your reply. Should you experience any problems with your current solutions, we will be more than happy to learn more on your circumstances that lead to the error you received + research your sample project, because there may be simpler/better solutions.
Hi.
I'm getting this error every time I want to open the ModelDesigner on the Module.Win or Win level. All I want is to add some common custom modules we implemented.
Our current fix is to move the registration to the constructor of WinModule.cs and wrap it with a design time check like:
public MyWindowsFormsModule() { InitializeComponent(); if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) { this.RequiredModuleTypes.Add(typeof(My.Module.CommonModule)); this.RequiredModuleTypes.Add(typeof(My.Module.Win.CommonWinFormsModule)); ... more modules } }
This worked until we added a ModelExtender to one of our common modules. Without it being loaded at design time I obviously can not change that property in the ModelDesigner. Furthermore it results in creating the UnusableNodes.xml file which informs there are no properties to be set as I "hacked" the values straight into the xml content of the Model.DesignedDiffs.xml.
As usual this is a elusive problem, because I might not be able to reproduce this in a sample project.
Help is greatly appreciated.
@Daniel: Technically, these side-effects (UnusableNodes.xml and inability to set custom model properties at design time) are expected if you do not add these modules as required. Would you please check out if other solutions from the S30927 thread meet your needs better?
@Dennis: Thanks for your quick response.
I already tried all mentioned options.
Could it be a problem, that all assemblies are included in the csproj and shown in Project Explorer?
>>
2. The solution I'm talking about only contains the 5 basic projects of XAF (Module, Module.Web, Module.Win, Web, Win). All references come by assemblies and not by another project reference. All assemblies are stored in a folder located in the Module project (same level as Module.csproj).
Could it be a problem, that all assemblies are included in the csproj and shown in Project Explorer?
<<
Thanks for your update, Daniel. It is difficult to answer your question without debugging. Would you please attach your problematic project in a separate ticket so we can research this behavior further?
@Ilya, Daniel:
Sporadically receive "assembly has been loaded twice" or "Dictionary already contains class info" error with XAF designers?
Please help us test the ultimate remedy in v19.2 by collecting tracing information from your projects.
We will send you the v19.2 build and simple instructions to upgrade your XAF solution. Once you happen to reproduce these errors, we will await the eXpressAppFramework.log file back.
This build will also allow you test our ITypeDiscoveryService implementation that gives tremendous performance boost and stability in designers.
Email XafTeam@devexpress.com if you are all in. Thanks!
Hi! Sorry for the late reply - notification got lost in the email.
Sadly I can't participate in testing because for XAF we have to stick to 18.1 with Windows XP support. It's the reality in the industrial area so far.
Hi! I have the same issue in my project, I will send the log file to th mentioned email address. DX version is 19.2
Update: I passed through all my projects in the solution and made sure to replace all file references to Project-to-Project. Now I can open the model editor without receiving "assembly has been loaded twice" or "Dictionary already contains class info" error.