0

I have a C# WPF project that refers to a VB.NET WPF project. Certain windows in the C# project use UserControls defined in the VB.NET project. Recently I have been unable to build the C# project because of these UserControls. The build output shows the following for each window that uses the VB.NET UserControl:

error MC1000: Unknown build error, 'Could not find assembly 'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly. Line 37 Position 134.'

The build error is resolved if I add a Microsoft.VisualBasic reference to the C# project's dependencies. However, this wasn't required until recently. I first noticed it with Visual Studio Preview 16.4 then changed back to Enterprise with 16.3. I'm currently using VS Enterprise 16.3.9 and now have the same issue there (even though it worked for this version before).

My question is, is it really necessary to add a Microsoft.VisualBasic reference to my C# project or is this something else?

Mikke.e
  • 58
  • 1
  • 9
  • it's hard to tell what could cause this. you should investigate the loaded assemblies with a tool like dependency walker or procmon and try to find out what was different. – Bizhan Dec 13 '19 at 12:24
  • Remove it and see if you get any compiler errors. You can open Solution Explorer and delete from the reference folder. – jdweng Dec 13 '19 at 12:27
  • If you mean remove the visual basic reference then I've tried that already. Same error shows up. – Mikke.e Dec 13 '19 at 12:28
  • 2
    Yes, it is required if your C# code happens to consume certain part of VB.NET libraries. Anyway that assembly is part of .NET Framework, or .NET Core, so adding such a reference won't increase your distribution size. – Lex Li Dec 13 '19 at 13:52
  • 1
    Did you just add some code relies on one of the things listed here https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic?view=netframework-4.8 You could potentially change a line of code to use some other method and remove the dependency on that dll. Which will take up memory when loaded. Probably not a huge amount of memory but you would also find what's going on. – Andy Dec 13 '19 at 15:29
  • @Andy I was unable to find any recent additions to the specific UserControl or anything the UserControl uses. However, for now I just added the Microsoft.VisualBasic reference to the C# project and will investigate further when I have time. I'll post any updates I find here. – Mikke.e Dec 16 '19 at 11:48

1 Answers1

3

If your referenced code relies on the Microsoft.VisualBasic assembly, the runtime needs to be able to find it when running your application.

Either add it as a direct reference from your application, or make sure that you set the Copy Local property of the reference to true in the VB.NET project.

mm8
  • 163,881
  • 10
  • 57
  • 88