2

I am getting the following error, when updating:

![Description

This hasn't been an issue before, and the project is referenced. In code:

// Add the SQL db connection
services.AddContext<LairageContext>(Configuration.GetConnectionString("SqlConnection"), ServiceLifetime.Transient);

This is from startup.cs

It is referenced in dependencies:

enter image description here

And in the project references:

<ItemGroup>
    <ProjectReference Include="..\Marel.LairageScanner.Context.Sql\Marel.LairageScanner.Context.Sql.csproj" />
    <ProjectReference Include="..\Marel.Models\Marel.Models.csproj" />
</ItemGroup>

So I truly don't understand why this is happening.

CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • Have you checked this answer? https://stackoverflow.com/a/73968711/2924577 – Nikhil Feb 26 '23 at 09:33
  • @Nikhil, no. It's already in the default project, Not just that, but it's in the same assembly – CorrieJanse Feb 26 '23 at 09:36
  • Okay, it is hard to tell what's going wrong. I suggest trying these if you haven't already: [Similar Question 1](https://stackoverflow.com/questions/61449890/ef-migration-could-not-load-assembly-ensure-it-is-referenced-by-the-startup-pr), [Similar Question 2](https://stackoverflow.com/questions/53521473/ef-core-migration-could-not-load-assembly-assemblyname) – Nikhil Feb 26 '23 at 09:45
  • The default project in the image is `Marel.LairageScanner.Context.Sql` while you show the project file of a project *referencing* it. Seems that *that* project should be the default project. – Gert Arnold Feb 26 '23 at 16:09
  • @GertArnold thought it's clear from the error message, but I've updated the image to show that it doeesn't matter what the default repository is. – CorrieJanse Feb 26 '23 at 21:35
  • @Nikhil, unfortunately, both my default project and startup project are correct. But the error in mine is different because the assembly can't find itself. – CorrieJanse Feb 26 '23 at 21:40
  • 1
    What .Net versions are you using for the various projects? They may not be compatible. – YungDeiza Feb 27 '23 at 15:22
  • In your Package Manager Console, what is the selected Default Project? – jomsk1e Mar 02 '23 at 03:58
  • @jomsk1e, I have tested with both... – CorrieJanse Mar 02 '23 at 04:10
  • @YungDeiza, 6 for all of them... however, I did convert the project from 5 to 6. So maybe there is something still missing, though I thought I did update everything. – CorrieJanse Mar 02 '23 at 04:10
  • 1
    @CorrieJanse - In .NET 6, there is a new feature called implicit SDK-style projects, which uses a simplified project file format. If you're using an implicit SDK-style project, it's possible that the project reference is not being resolved correctly. – Pranav Bilurkar Mar 02 '23 at 14:36
  • I would suggest using fuslogvw to debug the assembly loading issue so it will show you the details of the problem. https://techcommunity.microsoft.com/t5/iis-support-blog/fusion-log-viewer-fuslogvw-exe/ba-p/784396 – Dan Csharpster Mar 03 '23 at 17:56

3 Answers3

0

You say that your project is referencing itself. Why do you have an explicit reference in the project to itself?

Remove this, and try again.

If that doesn't resolve it: where is the reference to Marel.Lairage.Blazor in your project reference?

I would expect:

<ItemGroup>
    <ProjectReference Include="..\Marel.Models\Marel.Models.csproj" />
    <ProjectReference Include="..\Marel.Models\Marel.Lairage.Blazor.csproj" />
</ItemGroup>

And what is in your using in startup.cs where you say you are referencing these packages?

mss
  • 1
  • 1
0

Run fuslogvw to show you what is happening.

The steps are detailed in this Microsoft post or this one. Basically you setup this .net tool (its installed with Visual Studio), start it and then reproduce your issue and it will capture essentially verbose debug level details as to why the assemblies are failing to load. From there the solution should be much more straightforward. If you can share the output of fuslogvw, we can help finish resolving this issue.

Dan Csharpster
  • 2,662
  • 1
  • 26
  • 50
  • 1
    So turns out it was an pathing issue. The project was a copy from a different solution and was still referencing a path associated with the older solution - so in visual studio I was able to include the references to the local projects just fine, but when it came to building it didn't work. Thanks for your answer. – CorrieJanse Mar 04 '23 at 23:47
0

In my case, even after "Clean and Rebuild", PM Console was referencing a DLL in Debug/Build that wasn't supposed to exist, happened since I switched the StartupProject (and specifying the StartupProject in console didnt help)

Re-starting VS ensuring that the console memory is cleared might help

divay pandey
  • 152
  • 4
  • 8