realm-dotnet icon indicating copy to clipboard operation
realm-dotnet copied to clipboard

NRE when executing weaver

Open nirinchev opened this issue 3 years ago • 5 comments
trafficstars

I started updating my code to use Realm v10.10.0 but I now get the following error when attempting to build the solution.

The current solution uses 10.7.1 without problem. I have tried; • Cleaning the solution between each build • Applying the updates incrementally (10.8 worked 10.9 failed) • Uninstalling Realm 10.7.1, cleaning the solution, then installing 10.10.0

Build started...
1>------ Build started: Project: CrmMongo, Configuration: Debug Any CPU ------
1>Build started 1/03/2022 2:20:27 PM.
1>Target _GetProjectReferenceTargetFrameworkProperties:
1>Target ResolveProjectReferences:
1>Target CoreCompile:
1>  Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
1>Target FodyTarget:
1>  Fody: Fody (version 6.6.0.0 @ file:///C:/Users/Raymond.Brack/.nuget/packages/fody/6.6.0/netclassictask/Fody.dll) Executing
1>    Fody/Realm: Executing weaver Realm v10.10.0+a3777199226446b969610d6c14ff04caff18d482
1>  MSBUILD : error : Fody: An unhandled exception occurred:
1>  MSBUILD : error : Exception:
1>  MSBUILD : error : Failed to execute weaver C:\Users\Raymond.Brack\.nuget\packages\realm.fody\10.10.0\build\..\weaver\netstandard2.0\Realm.Fody.dll
1>  MSBUILD : error : Type:
1>  MSBUILD : error : System.Exception
1>  MSBUILD : error : StackTrace:
1>  MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 221
1>  MSBUILD : error :    at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 112
1>  MSBUILD : error : Source:
1>  MSBUILD : error : FodyIsolated
1>  MSBUILD : error : TargetSite:
1>  MSBUILD : error : Void ExecuteWeavers()
1>  MSBUILD : error : Object reference not set to an instance of an object.
1>  MSBUILD : error : Type:
1>  MSBUILD : error : System.NullReferenceException
1>  MSBUILD : error : StackTrace:
1>  MSBUILD : error :    at ModuleWeaver.Execute()
1>  MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 185
1>  MSBUILD : error : Source:
1>  MSBUILD : error : Realm.Fody
1>  MSBUILD : error : TargetSite:
1>  MSBUILD : error : Void Execute()
1>  MSBUILD : error :
1>  Fody: Finished Fody 219ms.
1>Done building target "FodyTarget" in project "CrmMongo.csproj" -- FAILED.
1>
1>Done building project "CrmMongo.csproj" -- FAILED.
1>
1>Build FAILED.
1>
1>MSBUILD : error : Fody: An unhandled exception occurred:
1>MSBUILD : error : Exception:
1>MSBUILD : error : Failed to execute weaver C:\Users\Raymond.Brack\.nuget\packages\realm.fody\10.10.0\build\..\weaver\netstandard2.0\Realm.Fody.dll
1>MSBUILD : error : Type:
1>MSBUILD : error : System.Exception
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 221
1>MSBUILD : error :    at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 112
1>MSBUILD : error : Source:
1>MSBUILD : error : FodyIsolated
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Void ExecuteWeavers()
1>MSBUILD : error : Object reference not set to an instance of an object.
1>MSBUILD : error : Type:
1>MSBUILD : error : System.NullReferenceException
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at ModuleWeaver.Execute()
1>MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 185
1>MSBUILD : error : Source:
1>MSBUILD : error : Realm.Fody
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Void Execute()

Originally posted by @RayBrack in https://github.com/realm/realm-dotnet/issues/2836#issuecomment-1060044165

nirinchev avatar Mar 07 '22 00:03 nirinchev

Hey @RayBrack moved your issue here to be able to focus on the specific differences between the two. Can you clarify some things:

  1. Is this a multiproject solution and did you make sure to update all projects to the same Realm version?
  2. What platform are you building this on and how you're building it? E.g. Visual Studio 2022 on Windows/Jebrains Rider on macOS?
  3. What kind of a project is this - I assume Xamarin.Forms? Are you using a .NET Standard project for the shared library?

Finally, how would you prefer to diagnose this further? One option would be for you to share your project privately with us and we can take it over from there? If that's not possible, then I can add some extra logging to our weaver code to try and understand where the exception is coming from, as the built-in logging doesn't appear to be sufficient in this case.

nirinchev avatar Mar 07 '22 00:03 nirinchev

Hi @nirinchev,

The solution contains two projects;

  1. A Windows service (console application) using .NET 6.0 and Realm 10.7.0
  2. A class library using .NET Standard 2.0 and Realm 10.7.0.

The development environment is VS2022 on Windows 10.

RayBrack avatar Mar 07 '22 22:03 RayBrack

I was able to trigger a NRE by adding <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> to my csproj. Do you by any chance have that in either of your project files?

nirinchev avatar Mar 07 '22 22:03 nirinchev

Hi @nirinchev,

Sorry to take so long to get back to you. Removing the above element from the csproj file fixed the issue. Thanks for your help.

RayBrack avatar Mar 14 '22 04:03 RayBrack

Thanks for confirming this. When we wrote the weaver, there was no way of opting out from the compiler adding TargetFrameworkAttribute on the compiled assembly, so we didn't handle the case where it might be missing. I'll keep the issue open as this is something we'd like to guard against.

nirinchev avatar Mar 14 '22 12:03 nirinchev

I ended up spending a number of hours on this issue, as it doesn't show up easily by a Google search. I'm anxious to evaluate Realm, so it's been a big blocker on getting it working with our existing codebase.

mistial-dev avatar Sep 18 '22 03:09 mistial-dev

Hey @mistial-dev sorry about your experience. We'll bump the priority here to make the error message more informative.

nirinchev avatar Sep 19 '22 14:09 nirinchev

I encountered this issue with a .Net Framework 4.7.2 project that I upgraded to Realm 11.6.1 tonight.

I added these lines to my .csproj file and the problem went away.

<PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> </PropertyGroup>

Is this the preferred solution, or do you have another approach?

careygister avatar Feb 05 '24 05:02 careygister